import re
file1 = '/Users/jian.wang13/code/huisu/0803/test.txt'
file2 = '/Users/jian.wang13/code/huisu/0803/eu2cnET7.csv'
f2 = open(file2,'w')
with open(file1,'r') as f:
for i in f:
#i1=i.strip().split(' ')
i1 = re.split('s+',i)
i2 = ','.join(i1)
i3 = i2.strip(',') + 'n'
print(i3)
f2.write(i3)
#print('@@@@@@@@@@@@@')
参考
python,实现将文档中全部空白字符用逗号替换 - Iceberg_710815 - 博客园



