网站首页  汉语字词  英语词汇  考试资料  写作素材  旧版资料

请输入您要查询的考试资料:

 

标题 用于统计项目中代码总行数的Python脚本分享
内容
    这篇文章主要介绍了用于统计项目中代码总行数的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 © 2002-2024 cuapp.net All Rights Reserved
更新时间:2025/5/17 20:22:52