I have a generator that should return lines from file, and I want to improve it later to return only specific lines:
def f():
with open ('a', 'r') as f:
while True:
l = f.readline()
if l:
yield l
else:
break
Now, this generator shuold be called from a function that shows the file always, something like:
def g():
my_generator = f()
while True:
print(my_generator.next() if SOME_CONDITION else 'waiting for new input')
# if got to StopIteration -> wait until a new line appears in file
How can I do this? can I recreate my_generator
after it died, when I get a new line (how would I know a line was added?)