我正在尝试将多行内容写入 Python 中的文本文件
with open('output.txt', 'w') as outfile:
outfile.write("open\n" +
"c:\files\file.scr"+
"close"
)
文件路径写错了,
open
c:iles\drawing.dwgclose
有人可以建议如何写文件路径吗?
最佳答案
你可以通过在前面添加r
来使字符串raw
:
with open('output.txt', 'w') as outfile:
outfile.write("open\n" +
r"c:\files\file.scr"+
"close"
)
关于python-3.x - 如何在 Python 中将文件路径写入 txt 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64074134/