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


Groups > comp.lang.python > #102923 > unrolled thread

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

Started byMatt Wheeler <m@funkyhat.org>
First post2016-02-14 23:58 +0000
Last post2016-02-14 23:58 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

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

FromMatt Wheeler <m@funkyhat.org>
Date2016-02-14 23:58 +0000
SubjectRe: Make a unique filesystem path, without creating the file
Message-ID<mailman.119.1455494336.22075.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web