Python统计项目代码总行数 用于统计项目中代码总行数的Python脚本分享

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

Python统计项目代码总行数 用于统计项目中代码总行数的Python脚本分享

  2021-03-21 我要评论
想了解用于统计项目中代码总行数的Python脚本讲解的相关内容吗,在本文为您仔细讲解Python统计项目代码总行数的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:统计项目代码总行数,Python脚本,下面大家一起来学习吧。

最近需要统计一下项目中代码的总行数,写了一个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)

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

猜您喜欢

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们