import os
count=[0,0]
paths=[]
file_count=[0]
def sum_code(path):
    if os.path.isfile(path):
        one_file(path)
    else:
        paths=os.walk(path)
        for i in paths:
            for j in i[2]:
                path=i[0]+"\\"+j
                one_file(path)
def one_file(file_path):
    if file_path[-3:]==".py":
        file_count[0]+=1
        tag=True
        with open(file_path,"r",encoding="utf-8") as file:
            for line in file:
                if line.startswith("\'\'\'")or line.startswith('\"\"\"'):
                    tag=not tag
                    continue
                elif (not line.startswith("#") and  len(line)) and tag==True:
                    count[0]+=1
                    count[1]+=1
                else:
                    continue
        print(file_path+f" 文件代码:{count[1]},总代码{count[0]}")
        count[1]=0
sum_code(r"C:\Users\Administrator\Desktop\01python\3.0")
print("#"*200)
print(f"读取py文件一共:{file_count[0]}")
print(f"总代码量为:{count[0]}")

相关文章:

  • 2022-01-18
  • 2022-01-21
  • 2022-12-23
  • 2021-08-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-24
猜你喜欢
  • 2022-01-13
  • 2022-12-23
  • 2021-10-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-01
相关资源
相似解决方案