I'm newbie to programming and in Python as well.
I wrote a function that implements the unix's tail:
def tail(file):
strin = open(file, 'r')
lis = strin.readlines()
lastline = lis[-1]
return lastline
strin.close()
But I think that it is not optimal in performance.
How can I improve?
You can use this Recipe from Collections.deque
def tail(filename, n=10):
'Return the last n lines of a file'
return deque(open(filename), n)
Refer this :- https://docs.python.org/2/library/collections.html#deque-recipes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With