How to resolve file IOError [errno 17] exists when opening a file?

I am trying to open a file for writing using the following:

fh = open("testfile", "w") 

But I get an exception:

IOError: [Errno 17] File exists!

I have recording rights and no race conditions. Does anyone know why I am getting an error message?

Thanks.

+4
source share
1 answer

wx mode is something new in Python 3.3 , and is documented to raise an error if the file already exists. If w+ mode works, it seems to me that the code posted in the question does not actually correspond to the returned error ...

0
source

Source: https://habr.com/ru/post/1485527/


All Articles