#自己的类如果实现了iter方法,就可以使自己的产生的实例是可迭代的,
#调用__iter__()方法(for将自动调用对象的iter方法活的迭代器),返回自己的迭代器
import collections
class hello_iter:
def __init__(self):
self.__data = collections.deque("abcdefg")
def __iter__(self):
return self
def next(self):
if len(self.__data) != 0:
return self.__data.pop()
raise StopIteration
if __name__ == "__main__":
a = hello_iter()
for i in a:
print i