Message91779
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. |
|
Date |
User |
Action |
Args |
2009-08-20 16:12:27 | eric.smith | set | recipients:
+ eric.smith, mvyskocil |
2009-08-20 16:12:27 | eric.smith | set | messageid: <1250784747.08.0.834744407946.issue6740@psf.upfronthosting.co.za> |
2009-08-20 16:12:25 | eric.smith | link | issue6740 messages |
2009-08-20 16:12:25 | eric.smith | create | |
|