代码行统计工具(python)
来源:互联网 发布:一般公司的网络维护 编辑:程序博客网 时间:2024/06/11 17:33
用python写的代码行统计工具。文件名为counter.py。可以统计代码文件中的注释行、代码行、空行和总行数。目前支持注释为//, /*...*/类型和注释为#类型的编程语言代码行统计。使用方法:
在counter.py的同级目录建立一个文件,命名为filelist.txt,在该文件中输入需统计的代码文件的绝对路径和文件名。如c:/test.c。每个文件名占一行。
counter.py代码如下:
import recommentline = 0blankline = 0codeline = 0def init(): global commentline, blankline, codeline commentline = 0 blankline = 0 codeline = 0def output(filename): global commentline, blankline, codeline print print "/*********************************************/" print "file name: " , filename print "code line: ", codeline print "comment line: ", commentline print "blank line: ", blankline print "total line: ", codeline + commentline + blankline print "/*********************************************/" def count_c_like(filename): try: f = open(filename, 'r') except IOError, e: print print e return None global commentline, blankline, codeline iscomment = False for eachLine in f: if iscomment: commentline += 1 if eachLine.find("*/", 0) != -1: iscomment = False elif re.match(" *//", eachLine) is not None: commentline += 1 elif re.match(" */\*", eachLine) is not None: commentline += 1 if re.search("/\*.*\*/", eachLine) is None: iscomment = True elif eachLine.isspace(): blankline += 1 else: codeline += 1 f.close() return "OK"def count_mk_like(filename): try: f = open(filename, 'r') except IOError, e: print print e return None global commentline, blankline, codeline for eachLine in f: if eachLine.isspace(): blankline += 1 elif re.match(" *#", eachLine) is not None: commentline += 1 else: codeline += 1 f.close() return "OK" def main(): try: f = open("filelist.txt", 'r') except IOError, e: print e raw_input('Press ENTER key to exit') return None global filename for eachLine in f: filename = eachLine.strip() if filename == '': continue init() result = "OK" if re.search("\.min$|\.mk$", filename) is not None: result = count_mk_like(filename) else: result = count_c_like(filename) if result == "OK": output(filename) f.close() raw_input('Press ENTER key to exit')if __name__ == '__main__': main()
- 代码行统计工具(python)
- 代码修改统计工具(python)
- 代码统计工具-python版本
- 代码行统计工具
- 代码行统计工具
- Python代码行统计
- Python 代码覆盖率统计工具 coverage.py
- Python 代码覆盖率统计工具 coverage.py
- Python实现代码行数统计工具
- 用Python编写C\C++代码统计工具
- 代码行统计工具V1.5
- 代码行统计工具V2.0
- 代码行统计工具V2.5
- 代码行统计工具 SourceCounterCN简介
- 代码行统计工具(C#)
- 代码行数统计工具
- java代码统计工具
- 代码统计工具
- 编程日记0123 至php微博应用开发
- PhoneGap 开发环境搭建
- 如何理解 Java 的跨平台特性?
- 我最喜爱的十大技术文档写作工具
- struts2的跳转配置极其作用和含义
- 代码行统计工具(python)
- 使用Keytool配置Tomcat的https服务
- SWT自定义组合框
- SWT分组框
- study in foshan
- SWT 图片复制到剪切板
- 浅谈oracle网络配置文件
- springmvc标签的使用
- swt中提供的复制粘贴功能.