From a588a329c32615bb73e240a1dca7b026554c7f83 Mon Sep 17 00:00:00 2001 From: Dominik Neise Date: Mon, 12 Feb 2018 09:43:05 +0100 Subject: [PATCH] remove ugly generator function --- protozfitsreader/__init__.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) 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)