#calclate_code_lines.py
import os
def afileline(f_path):
res = 0
f = open(f_path)
for lines in f:
if lines.split():
res += 1
return res
if name=='main':
host = 'E:'+os.sep+'develop'+os.sep+'dev_workspace'+os.sep+'AptanaStudio3'+os.sep+'webhost'
allfiles = 0
allline = 0
for root,dirs,files in os.walk(host):
for afile in files:
if(root.startswith(host+os.sep+'entries')):
continue
elif(root.startswith(host+os.sep+'.svn')):
continue
elif(root.startswith(host+os.sep+'.settings')):
continue
elif(root.startswith(host+os.sep+'logs')):
continue
elif(root.startswith(host+os.sep+'static')):
continue
elif(root.startswith(host+os.sep+'payload'+os.sep+'.svn')):
continue
elif(root.startswith(host+os.sep+'dist'+os.sep+'.svn')):
continue
elif(root.startswith(host+os.sep+'dsync'+os.sep+'.svn')):
continue
elif(root.startswith(host+os.sep+'hcache'+os.sep+'.svn')):
continue
elif(root.startswith(host+os.sep+'test'+os.sep+'.svn')):
continue
elif(root.startswith(host+os.sep+'webhost'+os.sep+'.svn')):
continue
elif(root.startswith(host+os.sep+'wsgi'+os.sep+'.svn')):
continue
elif(root.startswith(host+os.sep+'hcache'+os.sep+'templates'+os.sep+'.svn')):
continue
elif(root.startswith(host+os.sep+'dsync'+os.sep+'hcache'+os.sep+'.svn')):
continue
else:
ext = afile.split('.')
ext = ext[-1]
if (ext in ['py','css','js','html','txt','docx','wsgi']):
itpath = root+os.sep+afile
allfiles += 1
allline +=afileline(itpath)
print (root+os.sep+afile)
print ('Total: ',allfiles)
print ('Total lines:',allline) 之后可以将此改造下便于以后的代码统计
【相关推荐】
1. 特别推荐 :“php程序员工具箱”V0.1版本下载
2. Python免费视频教程
3. Python面向对象视频教程
以上就是计算代码行数的python代码示例的详细内容,更多请关注Gxl网其它相关文章!
查看更多关于计算代码行数的python代码示例的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did85119