用Python编写C\C++代码统计工具
来源:互联网 发布:巧克力键盘 知乎 编辑:程序博客网 时间:2024/06/05 18:47
代码参考:https://foofish.net/how-to-count-code.html
import osdef parse(path): in_multi_comment = False comments,blanks,codes = 0,0,0 with open(path,'r') as fp: for scline in fp.readlines(): scline = scline.strip() if scline == '' and not in_multi_comment: blanks += 1 elif scline.startswith('//') or \ (scline.startswith("/*") and scline.endswith("*/")) or \ (in_multi_comment and not scline.endswith("*/")): comments += 1 elif scline.startswith("/*") or scline.endswith("*/"): in_multi_comment = not in_multi_comment comments += 1 else: codes += 1 return {"comments":comments,"blanks":blanks,"codes":codes}def counter(path): if os.path.isdir(path): comments,blanks,codes = 0,0,0 list_dirs = os.walk(path) for root,dirs,files in list_dirs: for f in files: file_path = os.path.join(root,f) if file_path.endswith(".c") or file_path.endswith(".h"): stats = parse(file_path) comments += stats.get("comments") blanks += stats.get("blanks") codes += stats.get("codes") return {"comments":comments,"blanks":blanks,"codes":codes} else: return parse(path)if __name__ == '__main__': print (counter("你的代码路径"))
阅读全文
0 0
- 用Python编写C\C++代码统计工具
- 代码统计工具(支持C#,VB.NET)
- 代码统计工具(支持C#,VB.NET)
- C语言代码统计工具的源程序
- 代码行统计工具(C#)
- 扩展python 用C语言编写python扩展代码
- 【Python】用C语言编写Python模块
- 代码行统计工具(python)
- 代码修改统计工具(python)
- 代码统计工具-python版本
- C语言代码编写
- 编写 Objective-C 代码
- 编写 Objective-C 代码
- 编写 Objective-C 代码
- 用C语言编写Python扩展模块
- 用VS 编写 Python C扩展
- trace工具,c++/c#/python
- Objective-C代码行数统计
- 验证用户名,手机号,ip地址,邮箱,url,密码,汉字等等的工具类
- C语言面试题---逻辑短路问题
- xPath语法
- shiro实例 realm
- 软件测试知识
- 用Python编写C\C++代码统计工具
- [转]windows下实现微秒级的延时
- IMU9轴卡尔曼滤波
- Warning:android-apt plugin is incompatible with future version of Android Gradle plugin
- 第一次使用Android Studio时你应该知道的一切配置
- mysql update 多表
- 【软工】内聚耦合
- 查看/修改Linux时区和时间
- 搭建VPN