求Python 统计代码量程序
有吧友有能用的Python 统计代码量的代码吗?有的话希望发一下
谢谢
{:10_288:} {:10_288:} {:10_288:} import easygui as g
import os
def show_result(star_dir):
lines = 0
total = 0
text = ''
for i in source_list:
lines = source_list
total+=lines
text+='%s源文件%d个,源代码%d行\n'%(i,file_list,lines)
title = '统计结果'
msg = '您目前累计编写了%d行代码,完成进度:%.2f%%\n离10w行代码还差%d行'%(total,total/1000,100000-total)
g.textbox(msg,title,text)
def calc_code(file_name):
lines = 0
with open(file_name) as f:
print('正在分析:%s'%file_name)
try:
for each_line in f:
lines+=1
except UnicodeDecodeError:
pass
return lines
def search_file(start_dir):
os.chdir(start_dir)
for each_file in os.listdir(os.curdir):
ext = os.path.splitext(each_file)
if ext in target:
lines = calc_code(each_file)
try:
file_list+=1
except KeyError:
file_list=1
try:
source_list+=lines
except KeyError:
source_list=lines
if os.path.isdir(each_file):
search_file(each_file)
os.chdir(os.pardir)
#递归调用
target = ['.py']
file_list = {}
source_list = {}
g.msgbox('请打开代码所在文件夹','统计代码量')
path = g.diropenbox('请打开代码库:')
search_file(path)
show_result(path)
zz学编程 发表于 2021-5-29 09:53
这个无论是否是自己编写的都统计了
页:
[1]