【发布时间】:2019-02-26 09:51:14
【问题描述】:
我在 Windows 上,我的目录中不存在任何文件。
我很难弄清楚原因:
fid = open('L01A.txt', 'x')
fid.write('A')
fid.close()
fid = open('L01a.txt', 'x')
fid.write('a')
fid.close()
给我:
[Errno 17] 文件存在:'L01a.txt'。
【问题讨论】:
-
'x' :Open a file for exclusive creation. If the file already exists, the operation fails.你可以在这里获得更多信息programiz.com/python-programming/file-operation。 -
如果你想覆盖已经创建的文件,你可以使用'w'而不是'x'。或者您可以使用 'a' 附加到已经存在的文件内容。
-
你有正确的反应来编辑你的帖子! :)