|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import easygui as g
import os
code_type=['.py','.c','.cpp','.pas','.asm']
countc=countcpp=countpas=countasm=countpy=0
numpy=numc=numcpp=numasm=numpas=0
num_file=[numpy,numc,numcpp,numpas,numasm]
num_line=[countc,countcpp,countpas,countasm,countpy]
def find_code():
all_file=os.listdir('.')
for each_file in all_file:
if os.path.isfile(each_file):
if os.path.splitext(each_file)[1]==code_type[0]:
global numpy
numpy+=1
with open(each_file,encoding='utf-8') as f:
for each_line in f:
global countpy
countpy+=1
if os.path.splitext(each_file)[1]==code_type[1]:
global numc
numc+=1
with open(each_file,encoding='utf-8') as f:
for each_line in f:
global countc
countc+=1
if os.path.splitext(each_file)[1]==code_type[2]:
global numcpp
numcpp+=1
with open(each_file,encoding='utf-8') as f:
for each_line in f:
global countcpp
countcpp+=1
if os.path.splitext(each_file)[1]==code_type[3]:
global numpas
numpas+=1
with open(each_file,encoding='utf-8') as f:
for each_line in f:
global countpas
countpas+=1
if os.path.splitext(each_file)[1]==code_type[4]:
global numasm
numasm+=1
with open(each_file,encoding='utf-8') as f:
for each_line in f:
global countasm
countasm+=1
if os.path.isdir(each_file):
os.chdir(each_file)
find_code()
os.chdir(os.pardir)
g.msgbox('请打开你存放代码的文件夹')
path=g.diropenbox('请选择你存放代码的文件夹')
os.chdir(path)
find_code()
for each in num_line:
sum=0+each
spare=100000-sum
proportion=sum/100000
msg='您目前共累计编写了%d条代码,完成进度:%.2f\n离十万行代码还差%d行,请继续努力'%(sum,proportion,spare)
title='统计结果'
text=''
for i in range(5):
text+='%s源文件%d个,原代码%d行/n'%(code_type[i],num_file[i],num_line[i])
g.textbox(msg,title,text)
问题出在这:
- num_file=[numpy,numc,numcpp,numpas,numasm]
- num_line=[countc,countcpp,countpas,countasm,countpy]
复制代码
你把变量放进去,传递的只是值
也就是说,你对那些变量进行操作是不会改变列表里的值的。
你可以直接改变列表的值,不用变量。
|
-
|