我想避免在python的文本文件末尾写一个换行符.这是一个我有很多问题,我相信很容易修复.这是一个例子:
fileout = open('out.txt', 'w')
list = ['a', 'b', 'c', 'd']
for i in list:
fileout.write('%s\n' % (i))
Run Code Online (Sandbox Code Playgroud)
这会在文件末尾打印\n字符.如何修改我的循环以避免这种情况?
fileout = open('out.txt', 'w')
list = ['a', 'b', 'c', 'd']
fileout.write('\n'.join(list))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3976 次 |
| 最近记录: |