import collections class MyIterator(collections.Iterator): __slots__=['__i'] def __init__(self,i): self.__i=i def __next__(self): return self.__i.next() class MyIterable(collections.Iterable): __slots__=['__s'] def __init__(self,items=None): if items is None: items=[] self.__s=list(items) def __iter__(self): return MyIterator(iter(self.__s)) def __repr__(self): return "MyIterable(%s)" % repr(self.__s) a=MyIterable([5,43,2,1]) print a # Because collections.Iterator in not an iterator # in Python 2.6 (missing next() method) # we have exception here for x in a: print ">",x