Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Oscar Benjamin Newsgroups: comp.lang.python Subject: Re: Make a unique filesystem path, without creating the file Date: Wed, 17 Feb 2016 13:31:22 +0000 Lines: 38 Message-ID: References: <85egce6a8a.fsf@benfinney.id.au> <20160215230539.GA42677@cskk.homeip.net> <851t8d42rt.fsf@benfinney.id.au> <85twl830m3.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 yeAB9HB65nKdbx/F0F3sqgB6JVGZXq2NNkoL4o22xhJw== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '"""': 0.05; 'subject:file': 0.07; 'cc:addr:python-list': 0.09; 'benjamin': 0.09; 'exist.': 0.09; 'filesystem': 0.09; 'here?': 0.09; 'path.': 0.09; 'thread': 0.10; 'def': 0.13; 'explicitly': 0.15; '*do': 0.16; '2016': 0.16; 'cc:name:python list': 0.16; 'confusion': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'tests)': 0.16; 'wrote:': 0.16; "wouldn't": 0.16; 'exists': 0.18; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'saying': 0.22; 'exists.': 0.22; 'file.': 0.22; 'this:': 0.23; 'patch': 0.24; 'header:In-Reply- To:1': 0.24; '(e.g.': 0.27; 'message-id:@mail.gmail.com': 0.27; 'function': 0.28; 'name?': 0.29; 'asked': 0.29; 'code': 0.30; 'entry': 0.31; 'source': 0.33; 'open': 0.33; 'file': 0.34; 'received:google.com': 0.35; 'exist': 0.35; 'path': 0.35; 'unit': 0.35; 'but': 0.36; 'there': 0.36; 'received:209.85': 0.36; 'subject:: ': 0.37; 'say': 0.37; 'received:209': 0.38; 'mean': 0.38; 'why': 0.39; 'subject:the': 0.39; 'still': 0.40; 'some': 0.40; 'care': 0.60; 'your': 0.60; 'skip:u 10': 0.61; 'real': 0.62; 'different': 0.63; 'times': 0.63; 'oscar': 0.84; 'subject:Make': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=dPf9vHvRwkWNbfJbES28CtzKicOd0h3IYMbDuvHhy5M=; b=IYLXQw/ORhsol8BCe3KmDSqrrc78q2sTGiAof3pA8irfjhLB40IiT+flDVL2p82VS3 gP9E75fck0K/8VieCidodJb4WNasdqU6lqdpu9kM31VaVEjafMm096mbBPhqCj1gw5cg ExJzyuIHE7cH/ssZ12pcq5X49oOxuTrEXzzlXMEwuJwDvCYDMLM6u2+vLubaGY2Ned+z 9WxUUwLrtmauht/20UOwMGvtISob+vrPP6+OQEkkgzpRpsL/Iq+e5bBI4LT5awJVLqzq Lh/NkU4ZTv8EC1l8Xqk41bG8aKszaMl9ASjdaRU8qDf/ii8LjI4276I3lAQbMpYPiVxG ybqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type:content-transfer-encoding; bh=dPf9vHvRwkWNbfJbES28CtzKicOd0h3IYMbDuvHhy5M=; b=m7IewMx68/WHpc2mOf30Q0vVJQyGV71VlwSK/f8GsrTFBHIvnd1vb71ImHSZLxUF5L /JxgLDkAi1YPu80H2tQsqvALGArN2Yn+2CnWWj09i4HJPGeef3wuoESZP5oeKSk6keLp cDVyYX9L70X35MyZBQ9s6MN1vSt6XTQZHfFTJHoQ0Kc0HVGd8EH4SOj7YtjldeSHuuk5 Ltr97AxVDLyMls+ZNpKodI3X3WE6nhVpqk5nKHHNyrZrDJv6J4vzXsrXrJrO3pNJKNwf qNutfuvRbbYdXa/bBcotiSi7wg9s7JFIk8R+TBTeE8m/XF8xfgm0hsjIHGw6CZTsrVxJ yW7Q== X-Gm-Message-State: AG10YOTnVhkirB9bBoAyg4vk76OpgfxuBT6ASWWCWS3vQIoIWNqKpL7g4asEgJ8NI17fQBGYeCGb3L6KaANV7Q== X-Received: by 10.25.86.198 with SMTP id k189mr647112lfb.90.1455715902109; Wed, 17 Feb 2016 05:31:42 -0800 (PST) In-Reply-To: <85twl830m3.fsf@benfinney.id.au> 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:103050 On 16 February 2016 at 19:40, Ben Finney wrote= : > Oscar Benjamin writes: > >> If you're going to patch open to return a fake file when asked to open >> fake_file_path why do you care whether there is a real file of that >> name? > > I don't, and have been saying explicitly many times in this thread that > I do not care whether the file exists. Somehow that is still not clear? Sorry Ben I misunderstood. I think I can see the source of confusion which is in your first message: """ In some code (e.g. unit tests) I am calling =E2=80=98tempfile.mktemp=E2=80= =99 to generate a unique path for a filesystem entry that I *do not want* to exist on the real filesystem. """ I read that as meaning that it was important that the file did not exist. But you say that you don't care if the file actually exists in the filesystem or not and just want a unique path. What do you mean by unique here? The intention of mktemp is that the path is unique so that there would not exist a file of that name and if you opened it for writing you wouldn't be interfering with any existing file. Do you just mean a function that returns a different value each time it's called? How about this: count =3D 0 def unique_path(): global count count +=3D 1 return os.path.join(tempfile.gettempdir(), str(count)) -- Oscar