Help with two Python operators

33 views
Skip to first unread message

Paul McDonald

unread,
Mar 28, 2015, 12:14:52 PM3/28/15
to web...@googlegroups.com
In the Web2py Application Development Cookbook:

 p82    the  &=  operators


if not form:

# search flatpage according to the current request

query = db.flatpage.c==request.controller

query &= db.flatpage.f==request.function     <-----  what is going on here?

if request.args:

query &= db.flatpage.args==request.args(0)

else:

query &= (db.flatpage.args==None)|(db.flatpage.args=='')

query &= db.flatpage.lang==lang


Alos, p69    the   |   bianary or operator

alphabetical = User.first_name|User.last_name        <------  what is going on here?  
 

  Can anyone explain what these are doing?
Thank you in advance


Paul
 

Massimo Di Pierro

unread,
Mar 28, 2015, 12:31:11 PM3/28/15
to web...@googlegroups.com
   query &= db.flatpage.f==request.function

is the same as 

   query = query & (db.flatpage.f==request.function)

Build a query from another query
Instead

   alphabetical = User.first_name|User.last_name

is the same as 

   alphabetical = [User.first_name, User.last_name]

makes a list of fields to use for sorting.
Reply all
Reply to author
Forward
0 new messages