This program is used to open the file specified and to print the last 10 lines of the file.
Program:
import sys
def main():
line= []
last = []
filein = open(sys.argv[1],"r")
for a in filein:
line.append(a)
last = line[-10:]
for each in last:
print each
main()
While running python tail.py sample_file.txt in terminal, the programs prints the last 10 lines of the file "sample_file.txt".
No comments:
Post a Comment