diff --git a/protozfitsreader/__init__.py b/protozfitsreader/__init__.py index 20240f9..4b69078 100644 --- a/protozfitsreader/__init__.py +++ b/protozfitsreader/__init__.py @@ -170,16 +170,17 @@ def __init__(self, fname): rawzfitsreader.open(self.fname + ":Events") self.numrows = rawzfitsreader.getNumRows() self.run_id = 0 - self.generator = self.__generator() - - def __generator(self): - for _ in range(self.numrows): - event = L0_pb2.CameraEvent() - event.ParseFromString(rawzfitsreader.readEvent()) - yield Event(event, self.run_id) def __iter__(self): - return self.generator + return self + + def __next__(self): + event = L0_pb2.CameraEvent() + try: + event.ParseFromString(rawzfitsreader.readEvent()) + return Event(event, self.run_id) + except EOFError: + raise StopIteration def list_tables(self): return rawzfitsreader.listAllTables(self.fname)