Week 6
Lines of Code
Read a Python file whose name came from the command line, and count only the lines that are code.
A file name after the program name.
A count. The wrong number of arguments, or a file that is not Python, stops the program.
The question, more slowly
The question is: one command-line argument, a Python file, and you print how many lines are code. Blank lines do not count. Comments do not count. A comment is a line whose first non-space character is the comment mark. The wrong number of arguments, a missing file, or a file that is not Python, and the program stops.
Open the file and walk the lines. Decide for each line. Do not count while you are still holding the whole file as one string unless you split it first.
People count a comment that is indented, or they count a blank line of spaces. Strip the line before you decide. The spec's sample files are the cases to try.
Before you code
Make a three-line text file in the sandbox: a comment, a blank line, and one line of code. Count the code line by hand.