[Python-ideas] chdir context manager (original) (raw)

Joao S. O. Bueno jsbueno at python.org.br
Sat Jan 19 13:17:57 CET 2013


On 19 January 2013 10:10, Daniel Shahaf <d.s at daniel.shahaf.name> wrote:

I suggest this deserves a context manager:

with savedcwd(): foo()

But if doing that, why does "foo" have to implement the directory changing itself?

Why not something along:

with temp_dir("/tmp"): # things that perform in /tmp

directory is restored.

Of course that one function could do both things, depending ob wether a parameter is passed.

js -><-



More information about the Python-ideas mailing list