亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

python實(shí)現(xiàn)代碼行數(shù)統(tǒng)計(jì)示例分享

 更新時(shí)間:2014年02月10日 10:31:55   作者:  
這篇文章主要介紹了python實(shí)現(xiàn)代碼行數(shù)統(tǒng)計(jì)的示例,需要的朋友可以參考下

復(fù)制代碼 代碼如下:

#!/usr/bin/python

'''
        File      : count.py
        Author    : Mike
        E-Mail    : Mike_Zhang@live.com
'''
import sys,os

extens = [".c",".cpp",".hpp",".h"]
linesCount = 0
filesCount = 0

def funCount(dirName):
    global extens,linesCount,filesCount
    for root,dirs,fileNames in os.walk(dirName):
        for f in fileNames:
            fname = os.path.join(root,f)
            try :
                ext = f[f.rindex('.'):]
                if(extens.count(ext) > 0):
                    print 'support'
                    filesCount += 1
                    print fname
                    l_count = len(open(fname).readlines())
                    print fname," : ",l_count
                    linesCount += l_count
                else:
                    print ext," : not support"
            except:
                print "Error occur!"
                pass


if len(sys.argv) > 1 :
    for m_dir in sys.argv[1:]:       
        print m_dir
        funCount(m_dir)
else :
    funCount(".")       

print "files count : ",filesCount
print "lines count : ",linesCount

raw_input("Press Enter to continue")

使用方法
1、針對本目錄

復(fù)制代碼 代碼如下:

./count.py

2、統(tǒng)計(jì)多個(gè)目錄

復(fù)制代碼 代碼如下:

./count.py /tmp ~

相關(guān)文章

最新評論