本文摘自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的两种编程方式是什么
解析Python实现mq消息队列以及消息队列的优点
Python怎么读取excel文件
Python中subprocess模块级方法的介绍(附代码)
值得一看的Python高效数据处理
Python numpy函数中linspace实现创建等差数列的实例分享
Python中进程间数据通讯模块multiprocessing.manager的介绍
学Python要用什么软件
Python读什么
Python字典怎么根据值返回键
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » python去掉空白行的多种实现代码