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

WBOY
Release: 2016-06-06 11:25:50
Original
1368 people have browsed it

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

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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!