python 每个字符后面增加空格,怎么做?

如图所示,我想在每个数字后面加上一个空格,该如何操作啊?

# !/usr/bin/python27
# coding: utf8
'''
将文件中的每个字符后面加个空格
'''
with open('a.txt', 'r+') as filehandler:
    with open('newtxt.txt','w') as filehandler2:
        filehandler2.write(''.join([f+' ' for fh in filehandler for f in fh]))

温馨提示:答案为网友推荐,仅供参考
第1个回答  2014-12-30
import re
string = 'asdf32323313a1sd3213sad1f3d' 
pattern = re.compile('.{1,1}')
print(' '.join(pattern.findall(string)))

第2个回答  2014-12-30

0算数字么?

m = "00220202020202020222000200"
print ''.join(["%s " % i for i in m])

第3个回答  2014-12-30
你用文件读写的形式,遍历每个字符,遍历的时候追加空格试试
第4个回答  2018-05-29
str="002202020202022020220202"
newstr=" ".join([i for i in str])
print(newstr)