Python Line Counter

Yesterday I was looking for a Python source code line counter to give me a summary of some source files, but I couldn’t find a free one that would do the job as I wanted. So I created one. And you can have it for free (GNU GPL) – download it here:

Download Python Line Counter

Sample usage:


Input files:

Total lines:   1510
Code lines:    1111
Comment lines: 139
Blank lines:   260


4 responses to Python Line Counter

I’m back!

After playing with your script for a bit, I realized that your method of capturing “comment” lines is incomplete. You do not account for the fact that a comment may follow a statement/expression, like this:

name = “alec” # setting the name

Further, you do not account for docstrings at all. These should be regarded as “comments” because they are intended for human readers instead of the computer’s interpreter. (Well, python does use the docstrings, but only for reference inside the program.)

This script needs some work… anyone who needs an accurate reading of comments in their code, I would either improve upon this script, or write your own.

Hi Alec,

Whether to count the line type you’ve described as a code line or a comment line is subjective. I would consider that line a code line.

For comments I am only talking about “#” lines, so this excludes docstrings. The source is available so feel free to modify it to suit your individual needs. It was written according to my requirements, which it suits.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.