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

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Matt Wheeler <m@funkyhat.org>
Newsgroups comp.lang.python
Subject Re: Make a unique filesystem path, without creating the file
Date Sun, 14 Feb 2016 23:58:47 +0000
Lines 21
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>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
X-Trace news.uni-berlin.de Mh3ROx6+rYOqoib1AllGbgZpyP7dobaTgTSxFZtik+rA==
Return-Path <m@funkyhat.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'paths': 0.05; '*not*': 0.07; 'subject:file': 0.07; 'suffix': 0.07; 'cc:addr:python-list': 0.09; 'newly': 0.09; 'received:74.125.82.44': 0.15; '2016': 0.16; 'nonexistent': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'temp': 0.16; 'wrote:': 0.16; 'directory.': 0.18; '&gt;': 0.18; 'library': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'bonus': 0.20; 'strip': 0.22; 'cc:no real name:2**0': 0.22; 'feb': 0.23; 'consistent': 0.23; 'header:In-Reply-To:1': 0.24; 'message- id:@mail.gmail.com': 0.27; 'function': 0.28; 'file': 0.34; 'received:google.com': 0.35; 'header:Received:8': 0.35; 'could': 0.35; 'dir': 0.35; 'exist': 0.35; 'received:74.125.82': 0.35; 'should': 0.36; 'created': 0.36; 'subject:: ': 0.37; 'being': 0.37; 'subject:the': 0.39; 'still': 0.40; 'ever': 0.60; 'your': 0.60; 'real': 0.62; 'within': 0.64; 'guaranteed': 0.67; 'from:addr:m': 0.84; 'subject:Make': 0.91
X-Virus-Scanned Debian amavisd-new at membrane.funkyhat.net
X-Gm-Message-State AG10YOR0ag/hjQh8kHb7JoZwymZB8NM8hmXKTsSsk4wew3nNPffRRX/FbV+io3JfICXRAU4k7RhRQtEDBYJqew==
X-Received by 10.194.9.42 with SMTP id w10mr12665391wja.159.1455494328448; Sun, 14 Feb 2016 15:58:48 -0800 (PST)
In-Reply-To <CAG93HwHjKewu-VHUUc1jL=cU-pDNxVtKxx6ORyr+mdLLSJx2TA@mail.gmail.com>
X-Gmail-Original-Message-ID <CAG93HwGRsvcc=9rGgOA=oi6C-3pTk-Kr3g4dxCN0ivvixTVPWw@mail.gmail.com>
X-Content-Filtered-By Mailman/MimeDel 2.1.21rc2
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.21rc2
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Xref csiph.com comp.lang.python:102923

Show key headers only | 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