iter

daryn darynr at gmail.com
Mon Aug 9 12:11:37 EDT 2010


I'm just playing around with the iter function and I realize that I
can use the iterator returned by it long after the original object has
any name bound to it.  Example:

>>>a=[1,2,3,4]
>>>b=iter(a)
>>>b.next()
1
>>>a[1]=99
>>>a[3]=101
>>>del a
>>>b.next()
99
>>>b.next()
3
>>>b.next()
101

it seems as if the original object is never being garbage collected
even though there is no name bound to it.  Does the name bound to the
iterator object count as a reference to the original object for
garbage collection purposes?  Is there some way to retrieve/manipulate
the original object via the iterator?

Just trying to understand how this all works.

-thanks for any help you can give
daryn



More information about the Python-list mailing list