Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #36172 > unrolled thread
| Started by | Chris Angelico <rosuav@gmail.com> |
|---|---|
| First post | 2013-01-06 01:09 +1100 |
| Last post | 2013-01-06 01:09 +1100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Couting the number of lines of code of a python program Chris Angelico <rosuav@gmail.com> - 2013-01-06 01:09 +1100
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2013-01-06 01:09 +1100 |
| Subject | Re: Couting the number of lines of code of a python program |
| Message-ID | <mailman.119.1357394951.2939.python-list@python.org> |
On Sun, Jan 6, 2013 at 12:55 AM, chaouche yacine <yacinechaouche@yahoo.com> wrote: > 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). If you're using this entirely on your own code, one good way to solve the problem is to make your code always importable. Protect your top-level code with "if __name__=='__main__':" (and possibly put it into a function main() if that simplifies your code counting), and you should then be able to import it as-is, and all you'll do is define a bunch of functions/classes. But counting lines of code is a hairy thing to do. Do blank lines, comments, and multi-line strings count? ChrisA
Back to top | Article view | comp.lang.python
csiph-web