I have the following problem with python's "all" and generators:
G = (a for a in [0,1])
all(list(G)) # returns False - as I expected
But:
G = (a for a in [0,1])
all(G) # returns True!
Can anybody explain that?
UPDATE:
I swear I get this! Check this out:
In [1]: G = (a for a in [0,1])
In [2]: all(G)
Out[2]: True
I am using Python 2.6.6 with IPython 0.10.2, all installed within the Python(x,y) package. Strangely enough, I get "True" (above) when I use the Spider IDE, and "False" in pure console...
UPDATE 2:
As DSM pointed out, it seems to be a numpy problem. Python(x,y) loads numpy, and all(G) was actually calling numpy.all(G) rather then the builtin all(). A quick workaround is to write:
__builtins__.all(G)
Thank you all for your help!
-maciej
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…