Skip to content

Instantly share code, notes, and snippets.

@xiaotangyuan
Last active January 31, 2019 13:50
Show Gist options
  • Save xiaotangyuan/e28b54c371e8f2fe1ea70b172f1d510e to your computer and use it in GitHub Desktop.
Save xiaotangyuan/e28b54c371e8f2fe1ea70b172f1d510e to your computer and use it in GitHub Desktop.
"""
python tailf.py thefile
equals linux shell order : tail -f thefile
"""
import time
def trackline(thefile):
thefile.seek(0, 2)
while True:
line = thefile.readline()
if not line:
time.sleep(1)
continue
yield line
if __name__ == '__main__':
import sys
thefile = sys.argv[1]
thefile = open(thefile)
for line in trackline(thefile):
print(line.replace('\n', ''))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment