Skip to content

Instantly share code, notes, and snippets.

@sansyrox
Created January 26, 2020 19:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sansyrox/6ceb7ac53841d49419584c43d15609d9 to your computer and use it in GitHub Desktop.
Save sansyrox/6ceb7ac53841d49419584c43d15609d9 to your computer and use it in GitHub Desktop.
Create a Program to Imitate the working of the tail command in Linux
from collections import deque
def get_last(filename, n=5):
"""
Returns the last n lines from the file
"""
try:
with open(filename) as f:
return deque(f, n)
except OSError:
print("Error opening file: {}".format(filename))
raise
if __name__=="__main__":
get_last("test.txt")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment