Skip to content
Snippets Groups Projects
Commit 6931aea8 authored by Kien Le's avatar Kien Le
Browse files

Implement log file iterator

parent 28c92a19
No related branches found
No related tags found
1 merge request!191Read log files generated by users
...@@ -25,8 +25,20 @@ class LogFile: ...@@ -25,8 +25,20 @@ class LogFile:
def __iter__(self): def __iter__(self):
return self return self
def __next__(self): def __next__(self) -> List[str]:
return self.file.readline() line = self.file.readline()
if line == '':
raise StopIteration
while line == '\n':
line = self.file.readline()
packet = []
# We have to check that we are not at the end of the file as well.
while line != '\n' and line != '':
packet.append(line)
line = self.file.readline()
if line == '':
break
return packet
def __del__(self): def __del__(self):
self.file.close() self.file.close()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment