Friday, December 24, 2010

Tail Program In Python...

This program is used to open the file specified and to print the last 10 lines of the file.


import sys

def main(): 
 line= []
 last = []
 filein = open(sys.argv[1],"r")
 for a in filein:
 last = line[-10:]
 for each in last:
           print each

While running python sample_file.txt in terminal, the programs prints the last 10 lines of the file "sample_file.txt".

No comments:

Post a Comment