Re: generator object, next method

2005-09-08 Thread Terry Reedy
"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

Re: generator object, next method

2005-09-08 Thread Duncan Booth
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?

Re: generator object, next method

2005-09-08 Thread Diez B. Roggisch
[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

Re: generator object, next method

2005-09-08 Thread simonwittber
> 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. #-

Re: generator object, next method

2005-09-08 Thread Paul Rubin
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

Re: generator object, next method

2005-09-08 Thread Duncan Booth
[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

Re: generator object, next method

2005-09-08 Thread Peter Otten
[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

generator object, next method

2005-09-08 Thread simonwittber
>>> 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