Make a unique filesystem path, without creating the file

Jon Ribbens jon+usenet at
Mon Feb 22 19:53:51 EST 2016

On 2016-02-23, Ben Finney <ben+python at> wrote:
> Oscar Benjamin <oscar.j.benjamin at> writes:
>> What does unpredictable mean in this context? Maybe I'm reading too
>> much into that...
> I think you may be, yes. The request in this thread requires making
> direct use of the “generate a new valid temporary fielsystem path”
> functionality already implemented in ‘tempfile’.
> Implementations of that functionality outside of ‘tempfile’ are a fun
> exercise, but miss the point of this thread.

I think you have missed the point of your own thread.

You can't do what you wanted using tempfile, the only possible
answer is to choose a filename that is sufficiently random that
your hope that it is unique won't be proven futile. tempfile has
two main modes, mktemp which meets your requirements but should
never be used as it is insecure, and mkstemp which doesn't meet
your requirements because it fundamentally operates by actually
creating the file in question and relying on the filesystem to
guarantee uniqueness.

More information about the Python-list mailing list