Eric Smith <e...@trueblade.com> added the comment:

This isn't the right forum to ask for help. You should try
comp.lang.python, where someone would be happy to explain this to you.

Having said that, here's the explanation:

This is not a bug.

Disregarding side effects, the expression:
a = b or c

is essentially the same as:
if b:
 a = b
else:
 a = c

So your code is:
if (lambda x : x == 'foo'):
 cond = (lambda x : x == 'foo')
else:
 cond = (lambda x : x == 'bar')

And since "(lambda x : x == 'foo')" evaluates to True (it's a lambda, so
it's not None), you're really saying:
cond = (lambda x : x == 'foo')

And your examples follow from that.

You can further verify this with your c1 and c2:
>>> cond = c1 or c2
>>> cond
<function <lambda> at 0x00B3EA30>
>>> cond is c1
True

So, you're just setting cond to the first of the 2 lambdas.

----------
nosy: +eric.smith
resolution:  -> invalid
stage:  -> committed/rejected
status: open -> closed
type:  -> behavior

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue6740>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to