本文摘自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 dict怎么实现的
Python获取csv文本指定数据方法
r和Python哪个容易入门
Python如何计算时间差
Python是一种面向什么的语言?
Python3中时间处理与定时任务的方法介绍(附代码)
Python axis是什么意思
Python中pack和unpack用法介绍
Python写的贪吃蛇游戏例子_Python
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » python在每个字符后添加空格的实例