中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

利用python 統(tǒng)計(jì)源碼行數(shù)

2018-07-20    來(lái)源:open-open

容器云強(qiáng)勢(shì)上線!快速搭建集群,上萬(wàn)Linux鏡像隨意使用
原理先獲取所有文件,然后統(tǒng)計(jì)每個(gè)文件中代碼的行數(shù),最后將行數(shù)相加,思路很簡(jiǎn)單。
import os
import os.path
import time
rootdir = '文件路徑'
filelists = []

#遍歷文件
def getFile(rootdir):
    global filelists
    for parent,dirnames,filenames in os.walk(rootdir):
        for dirname in dirnames:
            getFile(os.path.join(parent,dirname)) #嵌套
        for filename in filenames:
            #print "filename is:"+ filename  
            filelists.append(os.path.join(parent,filename))

#統(tǒng)計(jì)一個(gè)文件的行數(shù)
def countLine(fname):
    count = 0
    for file_line in open(fname).xreadlines():
        if file_line != '' and file_line != '\n': #過(guò)濾掉空行
            count += 1
    print fname + '.....' , count
    return count

if __name__ == '__main__' :
    startTime = time.clock()
    getFile(rootdir)
    totalline = 0
    for filelist in filelists:
        totalline = totalline + countLine(filelist)
    print 'totalline:',totalline
    print 'done:%0.2f second' % (time.clock() - startTime)

標(biāo)簽: 代碼

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請(qǐng)聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請(qǐng)與原作者聯(lián)系。

上一篇:php去除html標(biāo)簽代碼

下一篇:限制文件下載速度php代碼