本文摘自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如何安装包vtk
Python判断闰年程序是什么
Python注释是什么
安装完Python怎么打开
Python字符串字母怎么取出
如何用Python画烟花
Python学哪个web框架好?2019 Python web框架排行
pycharm和Python区别
Python中什么是对象
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » python去掉空白行的多种实现代码