[Python-Dev] Rationale for NamedTemporaryFile?

Scott Dial scott+python-dev at scottdial.com
Wed Mar 21 11:06:53 CET 2007

Greg Ewing wrote:
> Gregory P. Smith wrote:
>> I prefer the default of "clean up after itself" as is to avoid leaving
>> temporary file turds on systems caused by us lazy programmers.
> Maybe instead of an option there should be a separate
> function with a different name, such as NewUniqueFile.
> For the use cases I have in mind, the file isn't really
> "temporary" at all. Or rather, only the name is temporary,
> as it ultimately gets renamed.

I'm in favor of adding such a function. I've already wrote my way around 
this missing feature before. The tempfile modules AFAIK is the only 
portable way to make a unique filename and open it without exposing a 
race condition. As it is, it's not that difficult to write this function 
yourselves using mkstemp directly, but I believe there is a great 
benefit to have it in the stdlib.


Scott Dial
scott at scottdial.com
scodial at cs.indiana.edu

More information about the Python-Dev mailing list