我有 str = 'some words\n'
并且我想将它打印到文件中
with open(newfile, 'a') as the_file:
the_file.write(str)
我怎么能按字面意思写 'some words\n'
而不是 'some words'
并在末尾输入?
最佳答案
请尝试像 str = "some words\\n"
这样的双反斜杠。
关于python - 在python中将纯字符串写入文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48003241/