Make a unique filesystem path, without creating the file
Thomas 'PointedEars' Lahn
PointedEars at web.de
Mon Feb 15 19:18:17 EST 2016
Gregory Ewing wrote:
> Ben Finney wrote:
>> One valid filesystem path each time it's accessed. That is, behaviour
>> equivalent to ‘tempfile.mktemp’.
>> My question is because the standard library clearly has this useful
>> functionality implemented, but simultaneously warns strongly against its
> But it *doesn't*,
Yes, it does.
> if your requirement is truly to not touch the filesystem at all, because
> tempfile.mktemp() *reads* the file system to make sure the name it's
> returning isn't in use.
But there is a race condition occurring between the moment that the
filesystem has been read and is being written to by another user. Hence the
deprecation in favor of tempfile.mkstemp() which also *creates* the file
instead, and the warning about the security hole if tempfile.mktemp() is
You can use tempfile.mktemp() only as long as it is irrelevant if a file
with that name already exists, or exists later but was not created by you.
Please do not cc me. / Bitte keine Kopien per E-Mail.
More information about the Python-list