Make a unique filesystem path, without creating the file
ben+python at benfinney.id.au
Sun Feb 14 20:19:49 EST 2016
Dan Sommers <dan at tombstonezero.net> 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
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
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 |
More information about the Python-list