class test(object):
def __init__(self):
pass
def __iter__(self):
return \"my string\"
o = test()
print iter(o)
Why does th
To answer your specific question. Python2 appears to check for the presence of a .next
class attribute:
>>> class test(object):
... next = None
... def __iter__(self):
... return self
...
>>> print iter(test())
<__main__.test object at 0x7fcef75c2f50>
An instance attribute won't do:
>>> class test(object):
... def __init__(self):
... self.next = None
... def __iter__(self):
... return self
...
>>> print iter(test())
Traceback (most recent call last):
File "", line 1, in
TypeError: iter() returned non-iterator of type 'test'