【发布时间】:2019-10-12 12:04:55
【问题描述】:
我想在与我的 python 文件相同的目录中创建一个文本文件,但我得到了 FileNotFounfError。我认为如果文件不存在,open() 应该创建一个新文件。
我的python文件:
with open("test.txt", "w") as f:
f.write("Test")
但我收到以下消息
Traceback (most recent call last):
File "C:/Users/POPOVA/Desktop/Programming/Algs/Stack Overflow/myAns.py", line 1, in <module>
with open("test.txt", "w") as f:
FileNotFoundError: [Errno 2] No such file or directory: 'test.txt'
感谢您的帮助
【问题讨论】:
标签: python python-3.x with-statement