[issue5178] Add context manager for temporary directory

Nick Coghlan report at bugs.python.org
Tue Oct 26 11:12:21 CEST 2010


Nick Coghlan <ncoghlan at gmail.com> added the comment:

Merging the interfaces for mkdtemp and TemporaryDirectory isn't going to happen.

mkstemp/mkdtemp are for when the user wants to control the lifecycle of the filesystem entries themselves. (Note that context management on a regular file-like object only closes the file, it doesn't delete it from the filesystem). They're also intended as relatively thin wrappers around the corresponding C standard library functionality.

The other objects in tempfile (TemporaryFile, TemporaryDirectory, etc) are for when the user wants the lifecycle of the Python object to correspond with the lifecycle of the underlying filesystem element.

That said, TD itself can be used to create the temporary directory without having to use it as a context manager (the underlying directory is created in __init__, not __enter__).

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5178>
_______________________________________


More information about the Python-bugs-list mailing list