Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Matt Wheeler 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: References: <85r3gf55k4.fsf@benfinney.id.au> 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: 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; '>': 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: X-Gmail-Original-Message-ID: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:102923 On 14 Feb 2016 21:46, "Ben Finney" wrote: > What standard library function should I be using to generate > =E2=80=98tempfile.mktemp=E2=80=99-like unique paths, and *not* ever creat= e 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