When I create a list by calling the list function on an iterator that was itself produced with the itertools.combinations function, sometimes I get an error like the following:
*** Error in argument: '(combinations(aDict,2))'
But if I call the same list in a print, len or isinstance function, it works as expected.
I initially got this behavior in a script, but I could most reliably reproduce it using pdb, so the code example involves calling set_trace on a sript and then typing on the interpreter:
from itertools import combinations
aDict={'a':1,'b':2,'c':3}
print(len(list(combinations(aDict,2))))
print(isinstance(list(combinations(aDict,2)),list))
print(list(combinations(aDict,2)))
len(list(combinations(aDict,2)))
isinstance(list(combinations(aDict,2)),list)
list(combinations(aDict,2))
print('Hello')
import pdb
pdb.set_trace()
Then typing these commands in the interpreter:
>>> ================================ RESTART ================================
>>>
3
True
[('a', 'b'), ('a', 'c'), ('b', 'c')]
Hello
--Return--
> c:\sw_dev\00_draft_development\02_scade\a429test\test_value_generator\pdbcomb.py(15)<module>()->None
-> pdb.set_trace()
(Pdb) len(list(combinations(aDict,2)))
3
(Pdb) isinstance(list(combinations(aDict,2)),list)
True
(Pdb) list(combinations(aDict,2))
*** Error in argument: '(combinations(aDict,2))'
(Pdb) len(list(combinations(aDict,2)))
3
(Pdb)
So my question is, what is causing the error, and why does it not happen if I wrap the same command as an argument to len?
(I run python 3.3.1 over Windows 7 in a 64-bit Intel machine)