generator object, next method
simonwittber at gmail.com
simonwittber at gmail.com
Thu Sep 8 04:17:42 EDT 2005
> Why is that? I thought gen.next is a callable and gen.next() actually
> advances the iterator. Why shouldn't gen.next always be the same object?
That is, in essence, my question.
Executing the below script, rather than typing at a console, probably
clarifies things a little.
Sw.
#-------------------
def iterator():
yield None
gen = iterator()
#gen.next is bound to x, and therefore, gen.next should not be GC?
x = gen.next
y = gen.next
print x
print y
print gen.next
#-------------------
More information about the Python-list
mailing list