用于統(tǒng)計(jì)項(xiàng)目中代碼總行數(shù)的Python腳本分享
來(lái)源:易賢網(wǎng) 閱讀:1198 次 日期:2015-04-24 09:41:06
溫馨提示:易賢網(wǎng)小編為您整理了“用于統(tǒng)計(jì)項(xiàng)目中代碼總行數(shù)的Python腳本分享”,方便廣大網(wǎng)友查閱!

這篇文章主要介紹了用于統(tǒng)計(jì)項(xiàng)目中代碼總行數(shù)的Python腳本分享,本文直接給出實(shí)現(xiàn)代碼,需要的朋友可以參考下

最近需要統(tǒng)計(jì)一下項(xiàng)目中代碼的總行數(shù),寫了一個(gè)Python小程序,不得不說(shuō)Python是多么的簡(jiǎn)潔,如果用Java寫至少是現(xiàn)在代碼的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)

關(guān)于代碼上的分析就到這里,例子比較簡(jiǎn)單。

更多信息請(qǐng)查看IT技術(shù)專欄

更多信息請(qǐng)查看網(wǎng)絡(luò)編程
由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢 | 簡(jiǎn)要咨詢須知 | 新媒體/短視頻平臺(tái) | 手機(jī)站點(diǎn)

版權(quán)所有:易賢網(wǎng)