with open(‘file1‘, encoding=‘utf-8‘) as inf, open(‘file2‘, ‘w‘, encoding=‘utf-8‘) as outf: for line in inf: print(*[ word for word in line.split()],file=outf) # outf.write(line) # outf.write(‘ ‘.join([word for word in line.split()])) # outf.write(‘\n‘)
原文:https://www.cnblogs.com/superniao/p/10544065.html