[Python-Dev] Warn about mktemp once again?
Guido van Rossum
guido at python.org
Tue Apr 29 01:22:42 CEST 2008
IMO mkstemp() is a major pain because you have to use raw file
descriptors on the return value. I'd much rather recommend
[Named]TemporaryFile which return streams.
On Mon, Apr 28, 2008 at 4:17 PM, <skip at pobox.com> wrote:
> 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()
> >>> 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.
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-Dev