tempfile Question

John Machin sjmachin at lexicon.net
Wed Jun 7 07:53:02 EDT 2006


On 7/06/2006 3:57 PM, Dennis Lee Bieber wrote:
> On Wed, 07 Jun 2006 09:56:13 +1000, John Machin <sjmachin at lexicon.net>
> declaimed the following in comp.lang.python:
> 
>> The dir, prefix and suffix parameters are passed to mkstemp().
> 	<snip>
>> So I'd be thinking about using the (deprecated) mktemp() instead, 
> 
> 	I think you passed over the mkstemp() variation. Granted, it, too,
> returns an opened file, along with the full pathname of the file, but it
> requires the caller to handle eventual disposal of the file.
> 
> 	Merely close the opened file; pass the pathname to the subprocess,
> await completion of subprocess, reopen the file for use in Python...
> Then at the end, close the file and use the pathname to delete the file
> from the system.

I passed over mkstemp() because (according to my reading of the manual), 
mkstemp() requires an *extra* step (close the file), leaving the 
situation then *exactly* the same as with mktemp() i.e. some pirate 
process may molest the file before the caller's child process can open 
the file.

Cheers,
John



More information about the Python-list mailing list