Wednesday 15 August 2012

Tail on python. Best performance implementation -



Tail on python. Best performance implementation -

i'm newbie programming , in python well. wrote function implements unix's tail:

def tail(file): strin = open(file, 'r') lis = strin.readlines() lastline = lis[-1] homecoming lastline strin.close()

but think not optimal in performance. how can improve?

you can utilize recipe collections.deque

def tail(filename, n=10): 'return lastly n lines of file' homecoming deque(open(filename), n)

refer :- https://docs.python.org/2/library/collections.html#deque-recipes

python performance deque

No comments:

Post a Comment