Iteratoration question
Rhodri James
rhodri at wildebst.demon.co.uk
Thu Apr 2 18:50:38 EDT 2009
On Thu, 02 Apr 2009 23:37:16 +0100, grocery_stocker <cdalten at gmail.com>
wrote:
>
>>
>> in summary: iterator is bound to one instance of "it", while some_func()
>> returns a new instance each time it is called.
>>
>> BUT
>>
>> while what you are doing is interesting, it is not the same as Python's
>> iterators, which use "yield" from a function and don't require storing a
>> value in a class. look for "yield" in the python docs. this comment
>> may
>> be irrelevant; i am just worried you are confusing the above (which
>> apart
>> from the mistake about instances is perfectly ok) and python's iterators
>> (which use next(), yield, etc).
>>
>
> Okay, one last question for now
>
[snip]
>
> How comes I can;t go over 'value' like in the following
>
>>>> for x in value:
> ... print x
> ...
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> TypeError: iteration over non-sequence
I refer you back to Andrew's answer. Your "value" object isn't an
iterator and doesn't obey the Iteration protocol. Expecting to be
able to iterate over it is a tad optimistic.
--
Rhodri James *-* Wildebeeste Herder to the Masses
More information about the Python-list
mailing list