Programming Examples
Python program to count the number of lines in the file
Write a Python program to display the number of lines in the file
Solution
fname=input("Enter the file name : ")
fp=open(fname,"r")
data=fp.readlines()
count=len(data)
print("Number of Lines in File Are : ",count)
fp.close()
Output
Enter the file name : myfile.txt
Number of Lines in File Are :Â 5