473,322 Members | 1,566 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Logical lines of code counter

I got bored with working on larger projects and wrote a little
script/module for counting logical (not physical) lines of Python code
in a file or directory. It uses ASTs generated by compiler.parse instead
of text manipulation functions, so it isn't incredibly fast, but the
speed is good enough to be usable for me.

If you want to take a look, the file is at
<http://ecritters.biz/linecount.py>. I don't really care about how
people license their modifications (and the GPL is longer than the
script itself), so it's licensed under the MIT License.

I'm sure there are a few bugs (AST nodes I forgot to count?), and I'd
appreciate being emailed if anyone finds one.
Jul 18 '05 #1
6 4074
If you want something which can do this and so much more, have a look at pylint.

http://www.logilab.org/projects/pylint

Cheers,

Tim

On Sun, 22 Aug 2004 21:44:17 -0400, Leif K-Brooks <eu*****@ecritters.biz> wrote:
I got bored with working on larger projects and wrote a little
script/module for counting logical (not physical) lines of Python code
in a file or directory. It uses ASTs generated by compiler.parse instead
of text manipulation functions, so it isn't incredibly fast, but the
speed is good enough to be usable for me.

If you want to take a look, the file is at
<http://ecritters.biz/linecount.py>. I don't really care about how
people license their modifications (and the GPL is longer than the
script itself), so it's licensed under the MIT License.

I'm sure there are a few bugs (AST nodes I forgot to count?), and I'd
appreciate being emailed if anyone finds one.
--
http://mail.python.org/mailman/listinfo/python-list

Jul 18 '05 #2
Tim Leslie wrote:
On Sun, 22 Aug 2004 21:44:17 -0400, Leif K-Brooks <eu*****@ecritters.biz> wrote:
I got bored with working on larger projects and wrote a little
script/module for counting logical (not physical) lines of Python code
in a file or directory.

If you want something which can do this and so much more, have a look at pylint.

http://www.logilab.org/projects/pylint


Neat-looking tool, but not really usable for me. It counts physical
lines, not logical lines; it doesn't seem to have an option to
recursively scan all sub-directories and files in a directory; and it
refuses to process a file if some of the modules code wants to import
aren't importable, which is the case with mod_python code.
Jul 18 '05 #3
On Sun, 22 Aug 2004 23:43:25 -0400, Leif K-Brooks <eu*****@ecritters.biz> wrote:
Tim Leslie wrote:

http://www.logilab.org/projects/pylint
Neat-looking tool, but not really usable for me. It counts physical
lines, not logical lines; it doesn't seem to have an option to
recursively scan all sub-directories and files in a directory; and it
refuses to process a file if some of the modules code wants to import
aren't importable, which is the case with mod_python code.


Ah ok, I guess that's quite a drawback. I've been keeping my eye out
recently for software development tools like pylint/pychecker, so if
you can find a tool which can provide better line count type
statistics I'd be interested to hear about it.

Cheers,

Tim

--
http://mail.python.org/mailman/listinfo/python-list

Jul 18 '05 #4
On Sun, 22 Aug 2004 23:43:25 -0400, Leif K-Brooks wrote:
Tim Leslie wrote:
On Sun, 22 Aug 2004 21:44:17 -0400, Leif K-Brooks
<eu*****@ecritters.biz> wrote:
I got bored with working on larger projects and wrote a little
script/module for counting logical (not physical) lines of Python code
in a file or directory.

If you want something which can do this and so much more, have a look at
pylint.

http://www.logilab.org/projects/pylint


Neat-looking tool, but not really usable for me. It counts physical lines,
not logical lines; it doesn't seem to have an option to recursively scan
all sub-directories and files in a directory; and it refuses to process a
file if some of the modules code wants to import aren't importable, which
is the case with mod_python code.


pylint counts both physical lines and logical lines, but all collected
values are not displayed in reports. You should easily add a new report to
display some additional information if you need it. Well, it lacks some
documentation but the code is quite clean and I would be happy to help.

It's also possible to recursivly scan for all python modules in a
given package ("pylint mypackage"). The problem with failing import is the
most annoying one. I plan to fix it, one day ;)

--
Sylvain Thénault LOGILAB, Paris (France).

http://www.logilab.com http://www.logilab.fr http://www.logilab.org
Jul 18 '05 #5
Hi Sylvain,

Since you're alive on this list, I thought I'd throw you a couple of questions:

1) Where should I best be asking pylint questions? The mailing list
looks a bit quite so I wasn't sure if I would get a reply.

2) Is there someway to specify a set of variables which won't throw
errors for being unused, eg _ when used as a dummy in a for/list comp.

3) Why does this trigger?

W0622 datacore.ns5 Ns5._parseHeaders 156 Redefining built-in '_'

The offending line is:

electrodes = [{} for _ in range(self.num_channels)]

Cheers

Tim

On Tue, 24 Aug 2004 10:34:16 +0200, Sylvain Thenault
<sy**************@nospam.logilab.fr> wrote:


On Sun, 22 Aug 2004 23:43:25 -0400, Leif K-Brooks wrote:
Tim Leslie wrote:
On Sun, 22 Aug 2004 21:44:17 -0400, Leif K-Brooks
<eu*****@ecritters.biz> wrote:

I got bored with working on larger projects and wrote a little
script/module for counting logical (not physical) lines of Python code
in a file or directory.
If you want something which can do this and so much more, have a look at
pylint.

http://www.logilab.org/projects/pylint


Neat-looking tool, but not really usable for me. It counts physical lines,
not logical lines; it doesn't seem to have an option to recursively scan
all sub-directories and files in a directory; and it refuses to processa
file if some of the modules code wants to import aren't importable, which
is the case with mod_python code.


pylint counts both physical lines and logical lines, but all collected
values are not displayed in reports. You should easily add a new report to
display some additional information if you need it. Well, it lacks some
documentation but the code is quite clean and I would be happy to help.

It's also possible to recursivly scan for all python modules in a
given package ("pylint mypackage"). The problem with failing import is the
most annoying one. I plan to fix it, one day ;)

--
Sylvain Thénault LOGILAB, Paris (France).

http://www.logilab.com http://www.logilab.fr http://www.logilab.org




--
http://mail.python.org/mailman/listinfo/python-list

Jul 18 '05 #6
On Tue, 24 Aug 2004 20:03:20 +1000, Tim Leslie wrote:
Hi Sylvain,
Hi !
Since you're alive on this list, I thought I'd throw you a couple of
questions:

1) Where should I best be asking pylint questions? The mailing list looks
a bit quite so I wasn't sure if I would get a reply.
the mailing list is the right place to ask pylint related questions. There
isn't a lot of traffic there, but you're almost sure to get an answer by
asking to this list (more than here, since I've not always the time to
read c.l.py).
2) Is there someway to specify a set of variables which won't throw errors for being unused, eg _ when used as a dummy in a for/list comp.
yes, see "good-names" option / configuration variable. But this will allow
the name anywhere in your program.
3) Why does this trigger?

W0622 datacore.ns5 Ns5._parseHeaders 156 Redefining built-in '_'

The offending line is:

electrodes = [{} for _ in range(self.num_channels)]


because I guess that at some point "_" is added to builtins. This is
usually the case with internationalizable programs using gettext. It seems
that pylint itself is importing a module which add this name to the
builtins, it shouldn't. I'll investigate into this...

regards
--
Sylvain Thénault LOGILAB, Paris (France).

http://www.logilab.com http://www.logilab.fr http://www.logilab.org
Jul 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Aaron Gray | last post by:
Is there a program that will give C++ code statistics, ie number of lines of code, number of classes, etc Aaron
19
by: Alex Vinokur | last post by:
Is there any tool to count C-program lines except comments? Thanks, ===================================== Alex Vinokur mailto:alexvn@connect.to http://mathforum.org/library/view/10978.html...
6
by: zoltix | last post by:
Hi, I would like to access to execute specific commands but the privileges are not enough from an aspx Page. Because this service run as IU_IISSERVER, therefore aspx hasn’t access to these...
4
by: tommcd24 | last post by:
Does anyone know of a utility or VS add-in to count code lines in a project or solution? I just had to provide 50 pages of code for copyright and had initially thought that would be nearly the...
4
by: Boki | last post by:
Hi All, Only 77 lines codes, need 30MB ram.... is that large? Can I use single webbrowser control to open two page at the same time? Best regard, Boki.
135
by: Xah Lee | last post by:
Tabs versus Spaces in Source Code Xah Lee, 2006-05-13 In coding a computer program, there's often the choices of tabs or spaces for code indentation. There is a large amount of confusion about...
1
by: gdarian216 | last post by:
okay I had a code that asked user to input a file name and instead i changed it to take the input from the command line. I now want to output results of some functions to an output file. I have...
19
by: Pavan | last post by:
Hi, I want to know if there is any software for measuring lines of code of my c++ application. I found out a tool, sloccount, but it gives only physical lines of code. I found out one more...
16
by: lovecreatesbea... | last post by:
It takes mu so time to finish this C source code line count function. What do you think about it? / ******************************************************************************* * Function ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.