Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Write a Python program to read last n lines of a file

def read_lastnlines(fname,n):
	with open('file1.txt') as f:
		for line in (f.readlines() [-n:]):
			print(line)

read_lastnlines('file1.txt',3)
 
PREVIOUS NEXT
Tagged: #Write #Python #program #read #lines #file
ADD COMMENT
Topic
Name
3+2 =