Programming Examples
Python program to display only last line of a text file
Write a program to display only last line of a text file
Solution
fname=input("Enter the file name : ")
fp=open(fname,"r")
data=fp.readlines()
print("Last Line : ",data[-1])
fp.close()
Output/ Explanation:
Enter the file name : myfile.txt
Last Line :Â ccc