Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #36171 > unrolled thread

Couting the number of lines of code of a python program

Started bychaouche yacine <yacinechaouche@yahoo.com>
First post2013-01-05 05:55 -0800
Last post2013-01-05 05:55 -0800
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

  Couting the number of lines of code of a python program chaouche yacine <yacinechaouche@yahoo.com> - 2013-01-05 05:55 -0800

#36171 — Couting the number of lines of code of a python program

Fromchaouche yacine <yacinechaouche@yahoo.com>
Date2013-01-05 05:55 -0800
SubjectCouting the number of lines of code of a python program
Message-ID<mailman.118.1357394322.2939.python-list@python.org>
  
Hello.

I'v written a small script that prints the number of lines
 of code of a python program to stdout (by module, function, class and 
method), the sources are available online hereĀ  https://www.assembla.com/code/tahar/subversion/nodes. The readme has an example usage as well as a trace of what the script prints.

The
 problem is that I'm using the inspect module, because it provides a 
nice function inspect.getsourcelines that takes a python object and 
return its number of lines of code. BUT, it works on live objects, that 
means one has to first import the module he wants to process, and this 
can have side effects (example : GUI programs).

So my question is
 how can one count the number of lines of code of a python program 
without importing it (static code analysis) ? 

Some people on IRC
 advised me to look for the AST module. Can you give me a little help on
 how to use this module to count the number of lines of code of a 
function/method ?

Thanks in advance for your help.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web