Am Wed, 04 Oct 2006 12:24:48 +0200 schrieb Peter Otten:

> 
> The older pre-__iter__() iteration style relying on __getitem__() still
> works:
> 
>>>> class A:
> ...     def __getitem__(self, index):
> ...             return [3,2,1][index]
> ...
>>>> for item in A():
> ...     print item
> ...
> 3
> 2
> 1
> 

Thanks! I see:

>>> class B:
...   def __iter__(self):
...     for i in xrange(3):
...       yield [3,2,1][i]
...
>>> myIter = B().__iter__()
>>> myIter.next()
3
>>> myIter.next()
2
>>> myIter.next()
1

Chris
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to