text = []
user = input('Enter text to write to file (\'quit\') to end: ')
text.append(user)
while user != 'quit':
user = input('Enter text to write to file (\'quit\') to end: ')
text.append(user)
res = '\n'.join(text)
with open('text.txt', 'w') as f:
f.write(res)
Enter text to write to file ('quit') to end: vash
Enter text to write to file ('quit') to end: the
Enter text to write to file ('quit') to end: stampede
Enter text to write to file ('quit') to end: quit
chrx@chrx:~/python/stackoverflow/10.11$ cat text.txt
vash
the
stampede
首先收集所有的输入,然后用
.join()
一次写入您可以将^{} 函数与
stop
哨兵一起使用,然后将生成的序列字符串与'\n'
连接起来输出:相关问题 更多 >
编程相关推荐