最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

计算代码行数的python代码示例

来源:动视网 责编:小采 时间:2020-11-27 14:24:23
文档

计算代码行数的python代码示例

计算代码行数的python代码示例:这篇文章主要介绍了python 统计代码行数简单实例的相关资料,需要的朋友可以参考下 python 统计代码行数简单实例送测的时候,发现需要统计代码行数于是写了个小程序统计自己的代码的行数。#calclate_code_lines.py import os def afileli
推荐度:
导读计算代码行数的python代码示例:这篇文章主要介绍了python 统计代码行数简单实例的相关资料,需要的朋友可以参考下 python 统计代码行数简单实例送测的时候,发现需要统计代码行数于是写了个小程序统计自己的代码的行数。#calclate_code_lines.py import os def afileli


这篇文章主要介绍了python 统计代码行数简单实例的相关资料,需要的朋友可以参考下

python 统计代码行数简单实例

送测的时候,发现需要统计代码行数

于是写了个小程序统计自己的代码的行数。

#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代码示例

计算代码行数的python代码示例:这篇文章主要介绍了python 统计代码行数简单实例的相关资料,需要的朋友可以参考下 python 统计代码行数简单实例送测的时候,发现需要统计代码行数于是写了个小程序统计自己的代码的行数。#calclate_code_lines.py import os def afileli
推荐度:
标签: 代码 计算 示例
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top