Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #103050
| From | Oscar Benjamin <oscar.j.benjamin@gmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Make a unique filesystem path, without creating the file |
| Date | 2016-02-17 13:31 +0000 |
| Message-ID | <mailman.206.1455715904.22075.python-list@python.org> (permalink) |
| References | <85egce6a8a.fsf@benfinney.id.au> <20160215230539.GA42677@cskk.homeip.net> <851t8d42rt.fsf@benfinney.id.au> <CAHVvXxQn04gVGGqq283_O7oAdg-k_djWLoNPnR=ejp2UCWG-bw@mail.gmail.com> <85twl830m3.fsf@benfinney.id.au> |
On 16 February 2016 at 19:40, Ben Finney <ben+python@benfinney.id.au> wrote:
> Oscar Benjamin <oscar.j.benjamin@gmail.com> 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 ‘tempfile.mktemp’ 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 = 0
def unique_path():
global count
count += 1
return os.path.join(tempfile.gettempdir(), str(count))
--
Oscar
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Make a unique filesystem path, without creating the file Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2016-02-17 13:31 +0000
csiph-web