Re: Couting the number of lines of code of a python program

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

  1. Sorry, I don't know what went wrong, here is another paste (hopefully this will work this time). If you prefer, this a link anchor to the function https://www.assembla.com/code/tahar/subversion/nodes/tahar.py?rev=8#ln340

    def count_loc(lines):
        nb_lines  = 0
        docstring = False
        for line in lines:
            line =line.strip()

            if line == "" \
               or line.startswith("#") \
               or docstring and not (line.startswith('"""') or line.startswith("'''"))\
               or (line.startswith("'''") and line.endswith("'''") and len(line) >3)  \
               or (line.startswith('"""') and line.endswith('"""') and len(line) >3) :
                continue
            
            # this is either a starting or ending docstring
            elif line.startswith('"""') or line.startswith("'''"):
                docstring = not docstring
                continue

            else:
                nb_lines += 1

        return nb_lines





    ----- Original Message -----
    From: Chris Angelico <>
    To:
    Cc:
    Sent: Saturday, January 5, 2013 4:25 PM
    Subject: Re: Couting the number of lines of code of a python program

    On Sun, Jan 6, 2013 at 2:17 AM, chaouche yacine
    <> wrote:
    > 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


    Ow-what? Something's gone wrong with all your whitespace, I think...
    can you paste again please?

    ChrisA
    --
    http://mail.python.org/mailman/listinfo/python-list
    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,611
    Gordon Beaton
    May 25, 2004
  2. chaouche yacine
    Replies:
    0
    Views:
    113
    chaouche yacine
    Jan 5, 2013
  3. Chris Angelico
    Replies:
    0
    Views:
    142
    Chris Angelico
    Jan 5, 2013
  4. Chris Angelico
    Replies:
    0
    Views:
    129
    Chris Angelico
    Jan 5, 2013
  5. Dave Angel
    Replies:
    1
    Views:
    112
    Roy Smith
    Jan 5, 2013
Loading...

Share This Page