"Paul Rubin" <"http://phr.cx"@NOSPAM.invalid> wrote in message
news:[EMAIL PROTECTED]
> Duncan Booth <[EMAIL PROTECTED]> writes:
>> 1) Every time you access gen.next you create a new method-wrapper
>> object.
>
> Why is that? I thought gen.next is a callable and gen.next() actually
> advances t
Paul Rubin wrote:
> Duncan Booth <[EMAIL PROTECTED]> writes:
>> 1) Every time you access gen.next you create a new method-wrapper
>> object.
>
> 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?
[EMAIL PROTECTED] wrote:
>>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.
Because bound methods are generated on the fly - google this group,
there have b
> 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.
#-
Duncan Booth <[EMAIL PROTECTED]> writes:
> 1) Every time you access gen.next you create a new method-wrapper object.
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?
--
http://mail.python.org/mailman/l
[EMAIL PROTECTED] wrote:
>
gen = iterator()
gen.next
>
gen.next
>
gen.next
>
gen.next
>
gen.next is gen.next
> False
>
>
> What is behind this apparently strange behaviour? (The .next method
> seems to alternately bind to two different objects)
It is a combination
[EMAIL PROTECTED] wrote:
gen = iterator()
gen.next
>
Behind the scene, gen.next is bound to _, i. e. it cannot be
garbage-collected. Then...
gen.next
>
a new method wrapper is created and assigned to _, and the previous method
wrapper is now garbage-collected. The memory locati
>>> gen = iterator()
>>> gen.next
>>> gen.next
>>> gen.next
>>> gen.next
>>> gen.next is gen.next
False
What is behind this apparently strange behaviour? (The .next method
seems to alternately bind to two different objects)
Sw.
--
http://mail.python.org/mailman/listinfo/python-list