python实现代码行数统计示例分享
#!/usr/bin/python'''
File : count.py
Author : Mike
E-Mail : Mike_Zhang@live.com
'''
import sys,osextens = [".c",".cpp",".hpp",".h"]
linesCount = 0
filesCount = 0def 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 : ",linesCountraw_input("Press Enter to continue")
使用方法
1、针对本目录
./count.py
2、统计多个目录
./count.py /tmp ~
您可能感兴趣的文章:
- python实现代码行数统计示例分享
- Python脚本实现代码行数统计代码分享
- Python脚本实现代码行数统计代码分享
- 统计代码行数(python实现)
- 代码行数统计(python实现)
- 代码行数统计的Java和Python实现
- python 统计代码行数,注释行数的简单实现
- 使用python统计文件行数示例分享
- python实现统计代码行数的方法
- python实现代码行数统计
- python脚本实现统计日志文件中的ip访问次数代码分享
- python实现的代码行数统计(纯代码)
- python脚本实现统计日志文件中的ip访问次数代码分享
- 使用python统计文件行数示例分享
- 《Python Case系列》一.Python实现统计项目的代码行数
- 代码行数统计(python实现)
- Python统计python文件中代码,注释及空白对应的行数示例【测试可用】
- python实现统计代码行数的方法
- 用python代码统计大文本文件行数
- python批量修改文件后缀示例代码分享