手机
当前位置:查字典教程网 >脚本专栏 >python >用于统计项目中代码总行数的Python脚本分享
用于统计项目中代码总行数的Python脚本分享
摘要:最近需要统计一下项目中代码的总行数,写了一个Python小程序,不得不说Python是多么的简洁,如果用Java写至少是现在代码的2倍。[c...

最近需要统计一下项目中代码的总行数,写了一个Python小程序,不得不说Python是多么的简洁,如果用Java写至少是现在代码的2倍。

[code]

import os

path="/Users/rony/workspace/ecommerce/ecommerce/hot-deploy/"

global totalcount

totalcount =0

def cfile (path):

allfiles = os.listdir(path)

for file in allfiles:

child = os.path.join(path,file)

if os.path.isdir(child):

cfile(child)

else:

filename,fileext= os.path.splitext(child)

print(fileext)

#file type need to calculate

if fileext in ['.java', '.jsp', '.html', '.htm', '.xml', '.sql', '.js', '.ftl', '.css','.groovy'] :

countf = len(open(child,'rU').readlines())

global totalcount

totalcount=totalcount+countf;

print(child)

print(countf)

cfile(path)

print(totalcount)

关于代码上的分析就到这里,例子比较简单。

【用于统计项目中代码总行数的Python脚本分享】相关文章:

写了个监控nginx进程的Python脚本

Python的一些用法分享

一个简单的python程序实例(通讯录)

Python FTP操作类代码分享

python实现2014火车票查询代码分享

Python操作列表的常用方法分享

python 图片验证码代码分享

python赋值操作方法分享

win7安装python生成随机数代码分享

使用python统计文件行数示例分享

精品推荐
分类导航