Created
March 30, 2012 15:24
-
-
Save skinp/2252263 to your computer and use it in GitHub Desktop.
Tail -f implementation in python
This file contains 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
import time | |
def tailf(filename): | |
f = open(filename, 'r') | |
f.seek(0,2) | |
while True: | |
line = f.readline() | |
if not line: | |
time.sleep(0.1) | |
continue | |
yield line | |
if __name__ == '__main__': | |
import sys | |
filename = sys.argv[1] | |
for i in tailf(filename): | |
print i, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment