|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- #/usr/bin/env python
- # -*- coding:utf-8 -*-
- import easygui as g
- import os
- def calculation(file1):
- file_lines=0
- with open(file1) as f:
- print '正在分析文件:%s'% file1
- try:
- for eachline in f:
- file_lines+=1
- except UnicodeDecodeError:
- pass
- return file_lines
- def search(directory):
- os.chdir(directory)
- for eachfile in os.listdir(os.chdir):
- ext=os.path.splitext(eachfile)[1]
- if ext in ['.py']:
- lines=calculation(eachfile)
- try:
- allfile[ext]+=1
- except KeyError:
- allfile[ext]=1
- try:
- alllines[ext]+=lines
- except KeyError:
- alllines[ext]=lines
- if os.path.isdir(eachfile):
- search(eachfile)
- os.chdir(os.pardir)
- def show(directory):
- text=''
- total_codes_lines=0
- for eachkey in alllines:
- linesssss=alllines[eachkey]
- text+='【%s】源文件有%d个,代码一共%d行\n'%(eachkey,allfile[eachkey],linesssss)
- total_codes_lines+=alllines[eachkey]
- msg='您目前所有代码量为%d行,完成进度为%.2f%% \n离10万行代码还差%d行,继续努力呦!' %(total_codes_lines,total_codes_lines/1000,100000-total_codes_lines)
- g.textbox(msg,'统计结果',text)
- allfile={}
- alllines={}
- g.msgbox('请打开您要检查的文件夹','统计代码量')
- path=g.diropenbox('请选择一个文件夹!')
- search(path)
- show(path)
复制代码
请问(1)第44行为什么报错?
text+='【%s】源文件有%d个,代码一共%d行\n'%(eachkey,allfile[eachkey],linesssss)
^
SyntaxError: invalid syntax
[Finished in 0.0s with exit code 1]
(2)关于show函数,感觉函数的定义(第38行)和调用(第55行)时都不需要参数,因为函数中没有用到......所以这两个参数我是不是可以不写?
第44行的错误是因为你的括号前半个不是英文输入的。。。包括46行和51行都有这个问题。。。
至于你说的那两个参数我感觉确实可以不要,不过你的alllines和allfile这两个参数要传入函数啊,不然函数找不到那两个字典还是报错的。。。
我把你的代码这样改了之后好像还是有点问题,你自己再看看吧  
|
|