|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 逆鳞丶樱之羽 于 2019-6-26 22:40 编辑
两个问题,其一:搜索['.py','.c','.cpp','.pas','.asm']这些没用 其二:当搜索格式不存在时,触发ccbox点continue不能循环文件打开的diropenbox
代码
如下:
import easygui as g
import sys
import os
g.msgbox('统计测量')
accumulate = 0
collect1 = 0 #i从1到5为py依序到asm
i1 = 0
collect2 = 0
i2 = 0
collect3 = 0
i3 = 0
collect4 = 0
i4 = 0
collect5 = 0
i5 = 0
while 1:
source = g.diropenbox()
for each in os.listdir(source):
if os.path.splitext(each)[1] in ['.py','.c','.cpp','.pas','.asm']:
if os.path.splitext(each)[1] in ['.py']:
collect1 += 1
with open(each) as f1:
f1.readline()
i1 += 1
elif os.path.splitext(each)[1] in ['.c']:
collect2 += 1
with open(each) as f2:
f1.readline()
i2 += 1
elif os.path.splitext(each)[1] in ['.cpp']:
collect3 += 1
with open(each) as f3:
f3.readline()
i3 += 1
elif os.path.splitext(each)[1] in ['.pas']:
collect4 += 1
with open(each) as f4:
f4.readline()
i4 += 1
else:
collect5 += 1
with open(each) as f5:
f1.readline()
i5 += 1
break
else:
g.msgbox('抱歉,未找到')
if g.ccbox('是否继续'):
pass
else:
sys.exit(0)
with open(source + '统计测量.txt','w') as f:
left = 10e6 - int(accumulate)
leftpercent = str(accumulate/10e6) + '\%'
msg = '我已经完成%d行代码,完成进度:%f \n 离10万行还差%d行,请继续努力' % accumulate,leftpercent,left
title = '统计结果'
f.write('''[.py]源文件%s个,总代码行数%s
[.c]源文件%s个,总代码行数%s
[.cpp]源文件%s个,总代码行数%s''' % collect1,i1,collect2,i2,collect3,i3)
f.write('''[.pas]源文件%s个,总代码行数%s
[.asm]源文件%s个,总代码行数%s''' % collect4,i4,collect5,i5)
if g.ccbox('是否继续'):
pass
else:
sys.exit(0)
还在for each in os.listdir(source):这个循环里,里边改break吧
|
|