Count the number of lines in a file – Python

This is a super simple tutorial. So simple, in fact, it is the shortest one I have ever written.

If you ever need to count the number of lines a file has in it and not even process the file, only count the lines, simply open the file and use a for loop to iterate over the number of lines and update an incrementer already in place. No need to even read the contents.

(View on GitHub Gist)

I told you this was a super simple and short tutorial. šŸ™‚

-le717

Advertisements

2 thoughts on “Count the number of lines in a file – Python

Triangular Reactions

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s