Couting the number of lines of code of a python program

Discussion in 'Python' started by chaouche yacine, Jan 5, 2013.

  1. 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 oflines of code of a
    function/method ?

    Thanks in advance for your help.
     
    chaouche yacine, Jan 5, 2013
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jazzy
    Replies:
    3
    Views:
    10,657
    Gordon Beaton
    May 25, 2004
  2. Chris Angelico
    Replies:
    0
    Views:
    165
    Chris Angelico
    Jan 5, 2013
  3. Chris Angelico
    Replies:
    0
    Views:
    151
    Chris Angelico
    Jan 5, 2013
  4. Dave Angel
    Replies:
    1
    Views:
    143
    Roy Smith
    Jan 5, 2013
  5. chaouche yacine
    Replies:
    0
    Views:
    131
    chaouche yacine
    Jan 5, 2013
Loading...

Share This Page