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

yipeiwu_com5年前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)

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

相关文章

Python打印斐波拉契数列实例

本文实例讲述了Python打印斐波拉契数列的方法。分享给大家供大家参考。具体实现方法如下: #打印斐波拉契数列 #!/usr/bin/python def feibolaqi(n):...

Django项目中使用JWT的实现代码

Django项目中使用JWT的实现代码

1.requiremwnts: Django版本:2.2 python版本:3.6 djangorestframework版本:3.1 djangorestframew...

Python GUI布局尺寸适配方法

如下所示: #coding=utf-8 #布局自定义尺寸 from tkinter import * class App: def __init__(self,master...

实例介绍Python中整型

Python中有以下几个基本的数据类型: 整数 int 字符串 str 浮点数 float 集合 set 列表 list 元组 tuple 字典 dict...

Python中条件选择和循环语句使用方法介绍

同C语言、Java一样,Python中也存在条件选择和循环语句,其风格和C语言、java的很类似,但是在写法和用法上还是有一些区别。今天就让我们一起来了解一下。 一.条件选择语句 Pyt...