Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #102923

Re: Make a unique filesystem path, without creating the file

From Matt Wheeler <m@funkyhat.org>
Newsgroups comp.lang.python
Subject Re: Make a unique filesystem path, without creating the file
Date 2016-02-14 23:58 +0000
Message-ID <mailman.119.1455494336.22075.python-list@python.org> (permalink)
References <85r3gf55k4.fsf@benfinney.id.au> <CAG93HwHjKewu-VHUUc1jL=cU-pDNxVtKxx6ORyr+mdLLSJx2TA@mail.gmail.com>

Show all headers | View raw


On 14 Feb 2016 21:46, "Ben Finney" <ben+python@benfinney.id.au> wrote:
> What standard library function should I be using to generate
> ‘tempfile.mktemp’-like unique paths, and *not* ever create a real file
> by that path?

Could you use tempfile.TemporaryDirectory and then just use a consistent
name within that directory.

It's guaranteed not to exist because the directory was only just created
and only you can write to it? Has the added bonus of still being reasonably
secure, to appease people like Mr PointedEars.

(If you need multiple nonexistent paths in the same dir then perhaps use
tempfile.NamedTemporaryFile with your newly created temp dir and an
arbitrary suffix, and strip the suffix off to get the name you actually
use.)

--
Matt Wheeler
http://funkyh.at

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Make a unique filesystem path, without creating the file Matt Wheeler <m@funkyhat.org> - 2016-02-14 23:58 +0000

csiph-web