代码统计

import os


def check_code(url):
    sum = 0
    s = os.walk(url)
    lock = 2
    ppp = url
    for i, j, x in s:

        for p in x:
            url = f'{i}\\{p}'
            count = 0
            if url.endswith(".py"):
                print(url)
                with open(url, 'r', encoding="utf8") as fr:
                    for line in fr:

                        if line.startswith('"')  or line.startswith("'"):
                            lock += 1
                        if lock % 2 == 0:
                            if line.startswith("#") or line == '\n':
                                continue
                            else:
                                count += 1
                                count = count
                                # print(line)
                    sum += count
    print(f"{ppp}    -->[ 总{sum-(lock-2)/2}行 ]")


check_code(r"D:\atm11")
posted @ 2019-08-23 19:30  cheerxiong  阅读(133)  评论(0编辑  收藏  举报