TECHIES WORLD

For Techs.... Techniques.... Technologies....

CpanelLinuxPython

How to check the number of lines in a file using Python

We can count the number of lines in a file using readline utility in Python.

count = len(open(filepath).readlines(  ))
print (count)

Here we need to replace filepath with the absolute path of the file.

Leave a Reply