python小程序-0006
来源:互联网 发布:mybatis sql使用别名 编辑:程序博客网 时间:2024/06/15 00:03
第6题:有个目录,里面是你自己写过的程序,统计一下你写过多少行代码。包括空行和注释,但是要分别列出来。
#!/usr/bin/env python3# -*- coding : utf-8 -*-import ostotal_lines = 0total_comment_lines = 0total_blank_lines = 0def analyzefile(filepath): linecnt = 0 blankcnt = 0 commentcnt = 0 global total_lines global total_comment_lines global total_blank_lines with open(filepath) as f: for line in f: #print(str(linecnt)+" "+line) line = line.strip() linecnt += 1 if line == '': blankcnt += 1 elif line[0] == '#' or line[0] == '/': commentcnt += 1 total_lines += linecnt total_comment_lines += commentcnt total_blank_lines += blankcntif __name__ == '__main__': dirpath = input("Please input dirpath: ") for file in os.listdir(dirpath): filepath = os.path.join(dirpath,file) if filepath.split('.')[-1] == 'py': analyzefile(filepath) print("Total codes line num is %d" % total_lines) print("Total comment lines num is %d" % total_comment_lines) print("Total blank lines num is %d" % total_blank_lines)
阅读全文
0 0
- python小程序-0006
- python小程序
- python 小程序
- python小程序
- python 简单小程序
- python小程序集锦
- python爬虫小程序
- Python小程序
- python小程序
- python练习小程序
- Python入门小程序
- python 查询小程序
- [python] 小程序
- Python里小程序
- Python通讯录小程序
- Python小程序
- python界面小程序
- python小程序
- F
- Android 动态修改app名称(市场和手机中显示两个不同的名称)
- Windows应用程序画正弦曲线
- python爬虫登录正方教务管理系统获取成绩数据
- NNpack的安装和配置
- python小程序-0006
- C/C++程序内存分配详解
- ubuntu16.04下py-faster-rcnn安裝
- 剑指offer——重建二叉树
- MySQL基础(7)——表的创建、更改和删除
- 杨辉三角
- LeetCode OJ 65 Valid Number[hard]
- HDU 1003 Max Sum
- Node express GET和POST获取参数的三种方法