Initial commit
This commit is contained in:
17
Solutions/8_2/follow.py
Normal file
17
Solutions/8_2/follow.py
Normal file
@@ -0,0 +1,17 @@
|
||||
# follow.py
|
||||
import os
|
||||
import time
|
||||
import csv
|
||||
|
||||
def follow(filename):
|
||||
'''
|
||||
Generator that produces a sequence of lines being written at the end of a file.
|
||||
'''
|
||||
with open(filename,'r') as f:
|
||||
f.seek(0,os.SEEK_END)
|
||||
while True:
|
||||
line = f.readline()
|
||||
if line == '':
|
||||
time.sleep(0.1) # Sleep briefly to avoid busy wait
|
||||
continue
|
||||
yield line
|
||||
Reference in New Issue
Block a user