[Python-Dev] Warn about mktemp once again? (original) (raw)

skip at pobox.com skip at pobox.com
Tue Apr 29 01:17:54 CEST 2008


Guido> Have we documented the alternatives well enough? 

I suppose we could document explicitly how to use mkstemp() in place of mktemp(), but the difference in return value is fairly modest:

>>> tempfile.mktemp()
'/var/folders/5q/5qTPn6xq2RaWqk+1Ytw3-U+++TI/-Tmp-/tmpV_5OLi'
>>> tempfile.mkstemp()
(3, '/var/folders/5q/5qTPn6xq2RaWqk+1Ytw3-U+++TI/-Tmp-/tmpmS7K4T')

and the argument list is quite similar as well:

>>> help(tempfile.mktemp)
Help on function mktemp in module tempfile:

mktemp(suffix='', prefix='tmp', dir=None)
...
>>> help(tempfile.mkstemp) 
Help on function mkstemp in module tempfile:

mkstemp(suffix='', prefix='tmp', dir=None, text=False)
...

Guido> In most cases NamedTemporaryFile will work, ...

It's API seems to be a bit farther from the mktemp API than that of mkstemp.

Skip



More information about the Python-Dev mailing list