Iteratoration question

grocery_stocker cdalten at gmail.com
Thu Apr 2 21:07:38 EDT 2009


On Apr 2, 4:41 pm, "andrew cooke" <and... at acooke.org> wrote:
> Robert Kern wrote:
> >> replace return with yield and it might work.
>
> >> i have to go eat, but if it doesn't read the python docs on iterators -
> >> for examplehttp://docs.python.org/reference/expressions.html#index-1825
>
> > No, .next() needs to be a regular function that returns a value. What he
> > needs
> > is an __iter__() method that returns self. Alternately, __iter__ could be
>
> yeah, sorry, i was in a rush and not thinking straight.  andrew

Okay, I was thinking more about this. I think this is also what is
irking me. Say I have the following..

>>> a = [1,2,3,4]
>>> for x in a:
...     print x
...
1
2
3
4
>>>

Would 'a' somehow call __iter__ and next()? If so, does python just
perform this magically?



More information about the Python-list mailing list