On Wed, 18 Apr 2007 19:45:50 -0700, Alex Martelli wrote: > 7stud <[EMAIL PROTECTED]> wrote: > ... >> Can you explain some of the details of why this code fails: > ... >> def next(self): >> for word in "Norwegian Blue's have beautiful >> plumage!".split(): >> yield word > > Sure, easily: a loop like "for x in y:" binds an unnamed temporary > variable (say _t) to iter(y) and then repeatedly calls _t.next() [or to > be pedantic type(_t).next(t)] until that raises StopIteration. > > Calling a generator, such as this next method, returns an iterator > object; calling it repeatedly returns many such iterator objects, and > never raises StopIteration, thus obviously producing an unending loop.
Thank you for that answer Alex, even though I didn't ask the question I was wondering the same thing myself. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list