Last active
January 31, 2019 13:50
-
-
Save xiaotangyuan/e28b54c371e8f2fe1ea70b172f1d510e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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