Quick way to calculate lines of code/comments in a collection of Python scripts?

Tomasz Rola rtomek at ceti.pl
Mon Oct 24 18:05:32 EDT 2016


On Mon, Oct 24, 2016 at 10:03:29AM +0100, Stephen Tucker wrote:
> Tomasz,
> 
> How about using the command prompt command FIND /C  on each of your source
> files as follows:
> 
> FIND/C "#" <SourceFile.py >>NumbersOfLinesContainingPythonComments.dat
> FIND/C /V "#" <SourceFile.py >>NumbersOfLinesNotContainingPythonComments.dat
> 
> You would end up with two files each with a column of line counts;
> 
> Import these lines into an Excel Spreadsheet and calculate whatever you
> like with them.

If this is what you really want to do, then why not. Albeit I would
rather go with sh script for this, with ability to process either a
directory or single file of Python code. Also, I tend to avoid tools
that are "click to work" as much as possible, so for me, this is not
good.

Using "find/c" or "grep|wc" might look like simple and quick and good
solution, but it may soon turn out to be too little, which is why I do
not consider sloccount to be an overkill (which you seem to
suggest). Especially that OP mentioned something about code
complexity, if memory serves. On my system, all it takes is:

(as root)   apt-get install sloccount

and:   sloccount alioth_nbody.lsp (or .py or what you like)

I guess it is similarly easy to install under other OSes, even under
Windows - I would try cygwin installer for this.

On the other hand, using Office (or equivalent) only to count lines
seems like royal excess. And if I want to calculate, I use lisp
interpreter interactively (believe it or not). Spritesheep, like
Excel, has some merits but I consider them poor choice for computing
anything important (I see no formula, I see no errors).

-- 
Regards,
Tomasz Rola

--
** A C programmer asked whether computer had Buddha's nature.      **
** As the answer, master did "rm -rif" on the programmer's home    **
** directory. And then the C programmer became enlightened...      **
**                                                                 **
** Tomasz Rola          mailto:tomasz_rola at bigfoot.com             **



More information about the Python-list mailing list