Source Lines of Code. One measure of the complexity of an application is the count
of the number of lines of source code. Often, this count discards
comment lines. We'll write an application to read Python source
files, discarding blank lines and lines beginning with
#, and producing a count of source
We'll develop a function to process a single file. We'll use
glob module to locate all of the
*.py files in a given directory.
which opens a file with the given
and examines all of the lines of the file. Each line should have
strip applied to remove leading and
trailing spaces. If the resulting line is of length zero, it was
effectively blank, and can be skipped. If the resulting line begins
# the line is entirely a comment, and can be
skipped. All remaining lines should be counted, and
returns this count.
) function which uses the path with the
glob.glob to expand all matching file names.
Each file name is processed with
to get the number of non-comment source lines. Write this to a
tab-delimited file; each line should have the form
For a sample application, look in your Python distribution for