def analyzePython(code_text):
        """Count how many line of code, comment, dosstr, purecode in one 
        Python script file.
        """
        code, comment, docstr = 0, 0, 0

        p1 = r"""(?<=%s)[\s\S]*?(?=%s)""" % ('"""', '"""')
        p2 = r"""(?<=%s)[\s\S]*?(?=%s)""" % ("'''", "'''")

        # count docstr
        for pattern in [p1, p2]:
            for res in re.findall(pattern, code_text)[::2]:
                lines = [i.strip() for i in res.split("\n") if i.strip()]
                docstr += len(lines)

        # count comment line and code
        lines = [i.strip() for i in code_text.split("\n") if i.strip()]
        for line in lines:
            if line.startswith("#"):
                comment += 1
            else:
                code += 1
        purecode = code - docstr  # pure code = code - docstr
        return code, comment, docstr, purecode
def analyzePython ( code_text ) : code , comment , docstr = 0 , 0 , 0 p1 = r"""(?<=%s)[\s\S]*?(?=%s)""" % ( '"""' , '"""' ) p2 = r"""(?<=%s)[\s\S]*?(?=%s)""" % ( "'''" , "'''" ) for pattern in [ p1 , p2 ] : for res in re . findall ( pattern , code_text ) [ : : 2 ] : lines = [ i . strip ( ) for i in res . split ( "\n" ) if i . strip ( ) ] docstr += len ( lines ) lines = [ i . strip ( ) for i in code_text . split ( "\n" ) if i . strip ( ) ] for line in lines : if line . startswith ( "#" ) : comment += 1 else : code += 1 purecode = code - docstr return code , comment , docstr , purecode
Count how many line of code, comment, dosstr, purecode in one 
        Python script file.