Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #36180
| Path | csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <yacinechaouche@yahoo.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; '(even': 0.05; 'classes,': 0.05; 'lines,': 0.05; 'main()': 0.07; 'objects,': 0.07; 'subject:code': 0.07; 'python': 0.09; '"if': 0.09; 'counting': 0.09; 'docstrings': 0.09; 'size)': 0.09; 'skip:o 60': 0.09; 'structure,': 0.09; 'subject:number': 0.09; 'gui': 0.11; 'subject:python': 0.11; 'code).': 0.16; 'simplifies': 0.16; 'skip:d 60': 0.16; 'skip:o 70': 0.16; 'subject:program': 0.16; 'top-level': 0.16; 'wrote:': 0.17; 'module,': 0.17; 'projects,': 0.17; 'jan': 0.18; 'code,': 0.18; 'module': 0.19; 'code.': 0.20; 'define': 0.20; 'mostly': 0.20; 'skip:= 10': 0.20; 'to:name :python-list@python.org': 0.20; 'sort': 0.21; 'import': 0.21; 'do.': 0.21; 'not,': 0.21; 'skip:_ 20': 0.22; 'to:2**1': 0.23; 'seems': 0.23; 'idea': 0.24; 'header:In-Reply-To:1': 0.25; 'am,': 0.27; 'possibly': 0.27; 'lines': 0.28; 'actual': 0.28; 'chris': 0.28; 'inspect': 0.29; "people's": 0.29; 'url:mailman': 0.29; "i'm": 0.29; 'function': 0.30; 'code': 0.31; '(and': 0.32; 'url:python': 0.32; '-----': 0.32; 'url:listinfo': 0.32; 'problem': 0.33; 'to:addr:python-list': 0.33; 'skip:d 20': 0.34; 'reply-to:addr:yahoo.com': 0.34; 'process,': 0.35; 'subject:': 0.36; 'but': 0.36; 'url:org': 0.36; 'email addr:python.org': 0.36; 'should': 0.36; 'display': 0.36; 'sent:': 0.37; 'subject:: ': 0.38; 'from:': 0.38; 'object': 0.38; 'skip:o 20': 0.38; 'to:addr:python.org': 0.39; 'takes': 0.39; 'url:mail': 0.40; 'think': 0.40; 'your': 0.60; 'first': 0.61; 'side': 0.61; "you'll": 0.62; 'email name:python-list': 0.62; 'solve': 0.62; 'information': 0.63; 'here': 0.65; 'header:Reply-To:1': 0.68; 'protect': 0.69; '2013': 0.84; 'picture.': 0.84; 'received:98.138.89.166': 0.84 |
| X-Yahoo-Newman-Property | ymail-3 |
| X-Yahoo-Newman-Id | 588973.22051.bm@omp1022.mail.ne1.yahoo.com |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1357399067; bh=mGekxcTujSdjBd9lFCMPgkXz+ah5zgllc4DDIx+LpSY=; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=gf00RbAAxMQ/nZGoxsV1vZCovnovg3aitgNzP9aZmTYFs4kVcZjKnsuNMvIWSq4KQxZk0eFzAM4kCPWzu+aaCD8Umc20KrfhoFG742XLWdKya2k+597BouIcWT81cJ0Q7jW531qqZXmHcLDHRRvPnqe1r96dlxV2lbeV2RpR0vc= |
| DomainKey-Signature | a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=Ovi94QMp6POu0tlVYjtvuEFEtw2EFEZHoqlJOYa8ICexjWbCOAZeYoxUTfNkNh2iLeZnYfac5gzGW3ePiImA4tmi7jYYslbUMYsPgGwdDHkEPQzRqDFrV0e6Aaw6YXJimbfh+Cf7xZ0G+c/bjg2s/T1kgSagWO11C/kxs8qR1mA=; |
| X-YMail-OSG | 5x5mHmQVM1k7onR9dFVxQRWnOpTcacI8qvmCpArOj7hy4jX J7BA5.BQnqe5wP80QaGooKbSxgszKN4C0tkVS7B.pBQK0w2RHTjPD_HXbTed Guc6B5XbDpCIZuWrQlc3Ob1d45Mnacdas7klpim5CVAWaH8d07C23Jf.hRK6 EGBoDdZI0Pi3R_HvzTLrfdmFb1Zimk7Vmv04tyyysZuVxnm8haAlt5dQ_DcL QbVsjOKScvQYY1C2AnAXqGB.EpTPvAs8nOVLYBJQ_QSQzy8IeP_zXvMxKGCe 6Ox017q9_iLfSRRGWMfL.7m8F6y9r7jGbbAHmZ35kGfRiugH26YiY3ttKADE qrx_.tMcitI2eeaJD.7sp4a1s7o4GK.OSBSkJ2JA4xAt.TCx7ZwCCbkGPGsu M1_R_Tk8L_wN64lGYyespU4rih7myNNnHBMnK4TmZRjFn5t2T2haL8_tejw2 oK0SKEccU5CFUD9ToHjQ9QlkZht1L8PZCKFPB8D2RHmfP_c5WhfUUJnxePiS KHQdtPqwbERkLz98V_A5U3ZhnVcgv |
| X-Rocket-MIMEInfo | 001.001, VGhlIGlkZWEgc3RhcnRlZCBvZmYgYXMgYSB2b2x1bWV0cmljIGluZm9ybWF0aW9uIG9mIG15IHByb2plY3RzLCBidXQgZXZvbHZlZCB0byBhIHNvcnQgb2YgY29kZSBicm93c2VyIHRoYXQgd291bGQgZGlzcGxheSBjbGFzc2VzLCBtZXRob2RzIGFuZCBmdW5jdGlvbnMgaW4gYSB0cmVlLWxpa2Ugc3RydWN0dXJlLCBhbmQgbm93IEkgbW9zdGx5IHdhbnQgdG8gdXNlIGl0IHdpdGggb3RoZXIgcGVvcGxlJ3MgY29kZSBhcyBhIHdheSB0byBoYXZlIHRoZSBiaWcgcGljdHVyZS4gU28gSSB3b3VsZCBzYXkgdGhhdCABMAEBAQE- |
| X-Mailer | YahooMailWebService/0.8.129.483 |
| References | <1357394154.35596.YahooMailNeo@web125506.mail.ne1.yahoo.com> <CAPTjJmrfZZ0aCoXA2biwKDFdKVupKxU0Jugpuck=L===Vz6=kA@mail.gmail.com> |
| Date | Sat, 5 Jan 2013 07:17:47 -0800 (PST) |
| From | chaouche yacine <yacinechaouche@yahoo.com> |
| Subject | Re: Couting the number of lines of code of a python program |
| To | Chris Angelico <rosuav@gmail.com>, "python-list@python.org" <python-list@python.org> |
| In-Reply-To | <CAPTjJmrfZZ0aCoXA2biwKDFdKVupKxU0Jugpuck=L===Vz6=kA@mail.gmail.com> |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=iso-8859-1 |
| Content-Transfer-Encoding | quoted-printable |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| Reply-To | chaouche yacine <yacinechaouche@yahoo.com> |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.122.1357399203.2939.python-list@python.org> (permalink) |
| Lines | 36 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1357399203 news.xs4all.nl 6984 [2001:888:2000:d::a6]:54805 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:36180 |
Show key headers only | View raw
The idea started off as a volumetric information of my projects, but evolved to a sort of code browser that would display classes, methods and functions in a tree-like structure, and now I mostly want to use it with other people's code as a way to have the big picture. So I would say that it is used both for my programs (to get a feeling of their size) as much as it is used for others' code.
> But counting lines of code is a hairy thing to do. Do blank lines,
> comments, and multi-line strings count?
The way I implmented it, they do not, particulary docstrings (even though it seems that many people think docstrings are actual code). My opinion on docstrings is that they're not instructions. I want to know how many lines of instructions a program has. Comments, blank lines and docstrings are not intructions.
Here is my implementation :
defcount_loc(lines):nb_lines =0docstring =Falseforline inlines:line =line.strip()ifline ==""\ orline.startswith("#")\ ordocstring andnot(line.startswith('"""')orline.startswith("'''"))\ or(line.startswith("'''")andline.endswith("'''")andlen(line)>3)\ or(line.startswith('"""')andline.endswith('"""')andlen(line)>3):continue# this is either a starting or ending docstringelifline.startswith('"""')orline.startswith("'''"):docstring =notdocstring continueelse:nb_lines +=1returnnb_lines
----- Original Message -----
From: Chris Angelico <rosuav@gmail.com>
To: python-list@python.org
Cc:
Sent: Saturday, January 5, 2013 3:09 PM
Subject: Re: Couting the number of lines of code of a python program
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 ams and
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
--
http://mail.python.org/mailman/listinfo/python-list
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Couting the number of lines of code of a python program chaouche yacine <yacinechaouche@yahoo.com> - 2013-01-05 07:17 -0800
csiph-web