Created
January 26, 2020 19:48
-
-
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
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
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