小甲鱼第35课后习题4,代码行数测试不出来
import easygui as gimport os
def show_result(start_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)
msg = "您目前一共累计编写了 %d 行代码,完成度:%.2f %%\n 离10万行代码还差 %d 行,请继续努力!" %(total,total/1000,100000-total)
title = '统计结果'
g.textbox(msg,title,text)
def culc_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 scan_dir(start_dir):
os.chdir(start_dir)
for file_name in os.listdir(os.curdir):
ext = os.path.splitext(file_name)
if ext in target:
lines = culc_code(file_name)
try:
file_list += 1
except KeyError:
file_list = 1
try:
source_list += lines
except KeyError:
source_list = lines
if os.path.isdir(file_name):
scan_dir(file_name)
os.chdir(os.pardir)
target = ['.c','.py']
source_list = {}
file_list ={}
g.msgbox('请打开您存放所有代码的文件夹...','统计代码量')
path = g.diropenbox('请选择你的代码库:','浏览文件夹')
show_result(path)
scan_dir(path)
你把最后两行换一下顺序试试 sunrise085 发表于 2020-9-12 17:00
你把最后两行换一下顺序试试
哈哈哈哈哈哈哈哈哈 天呐,被自己蠢哭了
页:
[1]