[Python-Dev] Why does TemporaryDirectory not wait for `__enter__`?

Robert Collins robertc at robertcollins.net
Sat Feb 26 19:48:29 CET 2011


On Sun, Feb 27, 2011 at 3:45 AM, cool-RR <cool-rr at cool-rr.com> wrote:

> I think that if someone calls `__enter__` directly, he takes the
> responsibility of calling `__exit__`, so we don't really have to help him
> with `__del__`.
> But other than that I understand the motivation for making it start on
> `__init__` rather then `__enter__`. I'll just make my own version of it that
> will work on `__enter__` instead.
> Thanks,
> Ram.

TempDir from 'fixtures' (http://pypi.python.org/pypi/fixtures) will do
what you want - __enter__ creates the directory, __exit__ deletes it.

Cheers,
Rob


More information about the Python-Dev mailing list