I am automatically generating filenames and I do not want there to be an overwrite. I am lazily using this little line of code
fd, filepath = tempfile.mkstemp(ext, prefix='odt_img_', dir=self.destPath)
os.close(fd) # just using the name and overwriting later
Later on I write to filepath, but I am not sure if mkstemp just adds some random letters or if it actually makes sure the name is unique.
tempfile.mkstemp only guarantees to create and open a new file with a name that does not exist. From the docs:
and the O_EXCL flag specifies:
Internally, mkstemp just loops through a random sequence trying to create a file that does not exist until it succeeds or runs out of “ideas” in which case it would fail with an IOError.