inline for and if

Chris Rebert clp2 at rebertia.com
Sat Oct 23 18:19:27 EDT 2010


On Wed, Oct 20, 2010 at 11:28 AM, Guy Doune <cesium5500 at yahoo.ca> wrote:
> Hello,
> I would get :
> db.table.field1, db.table.field2, etc.
> Inside a python instruction :
> db().select(HERE)
> It is web2py query actually.
>
> But I can't do this :
> db().select(
> for f in db['table'].fields:
>     if f not in fieldsBlackList:
>         db['table'][f],
> )
>
> Any idea?

Generator expression (http://www.python.org/dev/peps/pep-0289/ ):
db().select(db['table'][f] for f in db['table'].fields if f not in
fieldsBlackList)

Disclaimer: Never used web2py. I'm going by syntax alone here.

Cheers,
Chris
--
http://blog.rebertia.com



More information about the Python-list mailing list