def __iter__ ( self ) : def generator ( ) : for i , obj in enumerate ( self . _sequence ) : if i >= self . _limit : break yield obj raise StopIteration return generator
python generator' object has no attribute
Define a generator function and return it
def __iter__(self):
        """Define a generator function and return it"""
        def generator():
            for i, obj in enumerate(self._sequence):
                if i >= self._limit:
                    break
                yield obj
            raise StopIteration
        return generator