本文摘自php中文网,作者不言,侵删。
这篇文章主要介绍了关于python在每个字符后添加空格的实例,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下实例如下所示:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #!/usr/bin/env Python
# coding=utf-8
file = open( "chinese1.txt" , 'r' )
file2 = open(r 'chinese2.txt' , 'w' )# 返回一个文件对象
list1= file.readlines()
list2 = []
j = -1
for i in list1:
j+=1
if j % 3 == 2:
list1[j] = ( "=== \n" )
else :
list1[j] = i
# print (j)
# print (list1[j])
for i in list1:
file2.write(i)
file.close()
file2.close()
file = open(r 'two_1_2.0_100w.txt' , 'r' )
file2 = open(r "chinese1.txt" , 'w' )
file2.write( ' ' .join([f+ ' ' for fh in file for f in fh ]))
file.close()
file2.close()
|
相关推荐:
阅读剩余部分
相关阅读 >>
Python怎么读取和写入excel表格
Python是什么?
unity3d能用Python写吗
Python如何生成词云的方法
Python中std是什么
Python以太坊虚拟机实现py-evm的内容介绍
适合Python新手练习的项目
Python怎么念
Python绘制折线图和散点图的详细方法介绍(代码示例)
Python在groupby分组后提取指定位置记录方法
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » python在每个字符后添加空格的实例