本文摘自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单引号和双引号的区别
Python“与”怎么表示
Python的模块数据是哪里来的
Python file write () 方法概括及作用分析(实例)
Python怎么调用图像处理
Python 怎么向字符串中添加元素
Python怎么读txt文件
Python怎么安装pygame
Python中如何创建数值列表
Python什么意思中文
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » python在每个字符后添加空格的实例