Maybe everyone knows tail program for unix which is print last 10 lines of file by default. E.g.:
will print last 10 lines of log file and
tail -20 /var/log/message
will print last 20 lines.
So here are a few my realizations of this utility on python.
1. With subprocess
filename = raw_input('Enter file location: ')
n = int(raw_input('Enter number of lines to print: '))
f = subprocess.Popen(['tail','-%d' % n,filename],\
for i in range(0, n+1):
line = f.stdout.readline()