本文摘自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中使用deque保留最新n个元素的实现方法(代码)
Python会取代php吗?
Python缺点是什么
Python中none表示什么
Python防止sql注入方法介绍
Python数据结构:一个被低估的namedtuple(一)
Python图像处理之简单画板实现方法
django中使用定时任务的两种方法介绍
Python如何给series排序
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » python在每个字符后添加空格的实例