Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Ben Finney Newsgroups: comp.lang.python Subject: Re: Make a unique filesystem path, without creating the file Date: Mon, 15 Feb 2016 12:19:49 +1100 Lines: 38 Message-ID: References: <85r3gf55k4.fsf@benfinney.id.au> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: news.uni-berlin.de YyhmrUA3uF0a2vJsr+V2+Ah09W6ByrXztadRlGFUJ7Vg== Cancel-Lock: sha1:HzFQgF6uvvl1fM2CDCQ5ISpQKvQ= Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.010 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'paths': 0.05; 'only,': 0.07; 'subject:file': 0.07; 'filesystem': 0.09; 'implemented,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'example:': 0.10; '2016': 0.16; 'entry.': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'unnecessary.': 0.16; 'wrote:': 0.16; 'memory': 0.17; 'case.': 0.18; 'odd': 0.18; 'test.': 0.18; 'library': 0.20; 'name;': 0.22; 'feb': 0.23; 'mon,': 0.24; 'header :User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'equivalent': 0.27; 'question': 0.27; 'this.': 0.28; 'behaviour': 0.29; 'dan': 0.29; 'path,': 0.29; "i'm": 0.30; 'strongly': 0.30; 'entry': 0.31; 'post': 0.31; 'useful': 0.33; 'common': 0.33; 'path': 0.35; 'unit': 0.35; 'but': 0.36; 'should': 0.36; 'there': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'received:org': 0.37; 'files': 0.38; 'test': 0.39; 'subject:the': 0.39; 'to:addr:python.org': 0.40; 'real': 0.62; 'skip:n 10': 0.62; 'more': 0.63; 'goal': 0.64; '8bit%:27': 0.72; 'power': 0.72; '(your': 0.84; '_o__)': 0.84; 'accessed.': 0.84; 'failures.': 0.84; 'irrelevant': 0.84; 'received:125': 0.84; 'touching': 0.84; 'prone': 0.91; 'subject:Make': 0.91; '\xe2\x80\x9cthe': 0.93 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: jigong.madmonks.org X-Public-Key-ID: 0xAC128405 X-Public-Key-Fingerprint: 517C F14B B2F3 98B0 CB35 4855 B8B2 4C06 AC12 8405 X-Public-Key-URL: http://www.benfinney.id.au/contact/bfinney-pubkey.asc X-Post-From: Ben Finney User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) 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:102932 Dan Sommers writes: > On Mon, 15 Feb 2016 11:08:52 +1100, Ben Finney wrote: > > > I am unconcerned with whether there is a real filesystem entry of > > that name; the goal entails having no filesystem activity for this. > > I want a valid unique filesystem path, without touching the > > filesystem. > > That's an odd use case. It's very common to want filesystem paths divorced from accessing a filesystem entry. For example: test paths in a unit test. Filesystem access is orders of magnitude slower than accessing fake files in memory only, it is more complex and prone to irrelevant failures. So in such a test case filesystem access should be avoided as unnecessary. > If it's really just one valid filesystem path (your original post said > *paths*, plural), then how about __file__? or os.__file__? One valid filesystem path each time it's accessed. That is, behaviour equivalent to ‘tempfile.mktemp’. My question is because the standard library clearly has this useful functionality implemented, but simultaneously warns strongly against its use. I'm looking for how to get at that functionality in a non-deprecated way, without re-implementing it myself. -- \ “The most common way people give up their power is by thinking | `\ they don't have any.” —Alice Walker | _o__) | Ben Finney