[Python-ideas] x=(yield from) confusion [was:Yet another alternative name for yield-from]
Nick Coghlan
ncoghlan at gmail.com
Fri Apr 10 16:57:04 CEST 2009
Greg Ewing wrote:
> Nick Coghlan wrote:
>
>>>>> class Tricky(object):
>>
>> ... def __iter__(self):
>> ... return self
>> ... def next1(self):
>> ... print "Next 1"
>> ... Tricky.next = Tricky.next2
>
> I just tried using a class like that in a for loop, and
> it doesn't work. The next() method has to be defined in
> the class, because it's actually a special method (it
> has a slot in the type object).
Note that my example actually *does* modify the class as it goes along
(for exactly the reason you give - next() has to be defined on the class
or the interpreter will ignore it).
Is it possible you assigned to "self.next" instead of to "Tricky.next"
when trying it out?
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
More information about the Python-ideas
mailing list