string: __iter__()?
Peter Otten
__peter__ at web.de
Wed Oct 4 06:24:48 EDT 2006
mrquantum wrote:
> Am Wed, 04 Oct 2006 12:03:41 +0200 schrieb Fredrik Lundh:
>> really? iter("SomeString") works just fine for me.
> But then why doesn't dir('SomeString') show an __iter__ method? Seems to
> be implmented differently than with e.g. lists?
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
> Know why?
No idea. Perhaps nobody cared?
Peter
More information about the Python-list
mailing list