Skip to content

Instantly share code, notes, and snippets.

@swdream
Created August 20, 2014 10:59
Show Gist options
  • Save swdream/e8b1d38446edf54766e0 to your computer and use it in GitHub Desktop.
Save swdream/e8b1d38446edf54766e0 to your computer and use it in GitHub Desktop.
simulate tail -f command line
def tail_F(filename):
p = 0
with open(filename, 'r') as f:
while True:
f.seek(p)
new_line = f.read()
p = f.tell()
if new_line:
print new_line
print str(p).center(10).center(80, '=')
if __name__ == '__main__':
filename = 'whileloop.py'
tail_F(filename)
@hvnsweeting
Copy link

ôi anh Thành viết hay quá 👍

@hvnsweeting
Copy link

:| wtf with your indentation?
still using TAB?

@swdream
Copy link
Author

swdream commented Aug 20, 2014

paste lên đó nó mất tab :D

@hvnsweeting
Copy link

while True is disaster, see you top on how this use CPU.

Use sleep(0.1) or sleep(1)

@hvnsweeting
Copy link

paste lên đó nó mất tab

that is not the reason, the only reason is you still using tab, not spaces (or your editor is stupid)

@swdream
Copy link
Author

swdream commented Aug 20, 2014

print str(p).center(10).center(80, '=') => dòng này là đi ăn cắp nhé :D

@swdream
Copy link
Author

swdream commented Aug 20, 2014

that is not the reason, the only reason is you still using tab, not spaces (or your editor is stupid) => h còn ai đi sử dụng 4spaces khi code nữa hả m? tao có ngu đến thế đâu

@swdream
Copy link
Author

swdream commented Aug 20, 2014

@hvnsweeting blabla

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment