Python之删除代码中空白行
2015-11-23 10:38
591 查看
## 源码( delBlank.py )
## 说明
1. delBlank.py code.txt > tmp.txt
将code.txt中存在空行的代码全部清理掉,然后全部导出到tmp.txt之中。
2. 应用场景
当进行代码行数统计、或是要求编写软件说明书的doc版时需要进行处理。
import sys,os def readLines(fname): with open(fname,"r") as file: return file.readlines() lines = readLines(sys.argv[1]) for line in lines: if len(line.strip()) != 0: print line,
## 说明
1. delBlank.py code.txt > tmp.txt
将code.txt中存在空行的代码全部清理掉,然后全部导出到tmp.txt之中。
2. 应用场景
当进行代码行数统计、或是要求编写软件说明书的doc版时需要进行处理。
相关文章推荐
- selenium python (一) 开发环境搭建
- python中数组,元组,字典和字符串之间的转换
- python批量打多渠道包
- Python 最佳实践
- python中使用多继承
- 利用Sublimetext3&virtualenv 打造一个Web&Python IDE
- python学习之路之案例1(修改haproxy的配置文件,并实现下线、上线的功能)
- ubuntu 14.04 打开Python2.7 IDLE
- python模块导入过程
- python中的map、filter、reduce函数
- python参数传递那些事
- python使用pickle序列化对象至文件
- python内置数据类型
- Python Env
- python之路第五篇之装饰器:(进阶篇)
- 学习Python (三)
- leetcode之Implement Trie (Prefix Tree)
- python 监控jvm脚本
- python-02:学习路线
- python-03:用最简单快速的方法入门