本文摘自php中文网,作者不言,侵删。
这篇文章主要介绍了python去掉空白行实现代码,需要的朋友可以参考下测试代码 php.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | 1:www.php.cn
2:www.php.cn
3:www.php.cn
4:www.php.cn
5:www.php.cn
6:www.php.cn
7:www.php.cn
8:www.php.cn
9:www.php.cn
10:www.php.cn
11:www.php.cn
12:www.php.cn
13:www.php.cn
14:www.php.cn
15:www.php.cn
16:www.php.cn
|
python代码
代码一
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | # -*- coding: utf-8 -*-
'' '
python读取文件,将文件中的空白行去掉
'' '
def delblankline(infile, outfile):
infopen = open(infile, 'r' ,encoding= "utf-8" )
outfopen = open(outfile, 'w' ,encoding= "utf-8" )
lines = infopen.readlines()
for line in lines:
if line.split():
outfopen.writelines(line)
else :
outfopen.writelines( "" )
infopen.close()
outfopen.close()
delblankline( "php.txt" , "o.txt" )
|
代码二
阅读剩余部分
相关阅读 >>
Python tuple怎么用
用cmd写Python怎么换行
Python标准库是什么
Python获取代理ip的实例分享
Python如何打印出菱形与三角形以及矩形的代码示例分享
Python中yield什么意思
Python里print是什么意思
Python怎么安装第三方库?
Python中tornado的同步与异步i/o的介绍(附示例)
Python中index的用法是什么
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » python去掉空白行的多种实现代码