On 2017-09-06 08:37, Thomas Devoogdt wrote:
> Is there a reason why multiple AND statements are converted like this.
> 
> 
> (stm1) & (stm2) & (stm3)
> 
> ->
> 
> (((stm1) AND (stm2)) AND (stm3))
> 
> and not
> 
> ((stm1) AND (stm2) AND (stm3))
> 

This is because '&' which is __and__ operator in Python is binary and
Python evaluate from left to the right.
So the first "(stm1) & (stm2)" is evaluated which result in the
construction of "And((stm1, stm2))".
After that "And((stm1, stm2)) & (stm3)" is evaluated which result in the
construction of "And((And((stm1, stm2)), stm3))" which is the expression
you get.

If you really want to have your simplified version, you must use the And
operator instead of the syntax sugar __and__:

    And((stm1, stm2, stm3))

Now I anticipate the question about optimizing the __and__ operator to
append to the first And instead of encapsulate. I think it is an
optimization that will increase code complexity for a very small gain (2
chars).

-- 
Cédric Krier - B2CK SPRL
Email/Jabber: cedric.kr...@b2ck.com
Tel: +32 472 54 46 59
Website: http://www.b2ck.com/

-- 
You received this message because you are subscribed to the Google Groups 
"python-sql" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to python-sql+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to