用于统计项目中代码总行数的Python脚本分享
最近需要统计一下项目中代码的总行数,写了一个Python小程序,不得不说Python是多么的简洁,如果用Java写至少是现在代码的2倍。
[code]
importos
path="/Users/rony/workspace/ecommerce/ecommerce/hot-deploy/"
globaltotalcount
totalcount=0
defcfile(path):
allfiles=os.listdir(path)
forfileinallfiles:
child=os.path.join(path,file)
ifos.path.isdir(child):
cfile(child)
else:
filename,fileext=os.path.splitext(child)
print(fileext)
#filetypeneedtocalculate
iffileextin['.java','.jsp','.html','.htm','.xml','.sql','.js','.ftl','.css','.groovy']:
countf=len(open(child,'rU').readlines())
globaltotalcount
totalcount=totalcount+countf;
print(child)
print(countf)
cfile(path)
print(totalcount)
关于代码上的分析就到这里,例子比较简单。