Missing feature in tempfile module (Was: os independent temp dir?)

Paul Moore paul.moore at atosorigin.com
Thu May 10 11:13:23 EDT 2001


m.hadfield at niwa.cri.nz ("Mark Hadfield") <m.hadfield at niwa.cri.nz> writes:

> Responding to a couple of different posts in this thread:
> 
> > On the Mac it appears you should store files in the "Temporary Items"
> > folder of the boot volume (don't ask me how you find the boot volume).
> 
> Luckily, one of the contributors to the tempfile module did know that,
> witness the following code snippet.

Interestingly, this is in tempfile.gettempdir(). But this function is
neither documented, nor included in __all__.

The tempdir variable is used to configure mktemp() - at leat that's
how it's documented - and has a value of None until the first call to
mktemp().

So, the following get you a temporary directory name:

    import tempfile

    # Not documented or exported in __all__
    temp1 = tempfile.gettempdir()

    # Nasty hacky need to call mktemp() first to initialise
    # Also not documented to work...
    tempfile.mktemp()
    temp2 = tempfile.tempdir

    # Bizarre and silly
    import os.path
    temp3 = os.path.dirname(tempfile.mktemp())

Please, can we have gettempdir() formally documented and exported???

Paul.




More information about the Python-list mailing list