[Python-ideas] chdir context manager

Guido van Rossum guido at python.org
Sat Jan 19 18:18:18 CET 2013


On Sat, Jan 19, 2013 at 6:57 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:
> -1 from me
>
> I consider caring about the current directory to be an anti-pattern -
> paths should be converted to absolute ASAP, and for invocation of
> other tools that care about the current directory, that's why the
> subprocess APIs accept a "cwd" argument. I certainly don't want to
> encourage people to unnecessarily rely on global state by providing a
> standard library context manager that makes it easier to do so.

Also it's not thread-safe.

TBH I think if people are doing this today it's probably a good idea
to suggest that they make their code more reliable by turning it into
a context manager; but I think having that context manager in the
stdlib is encouraging dubious practices. (The recommendation to use
absolute filenames is a good one but not always easy to implement
given a large codebase relying on the current directory.)

-- 
--Guido van Rossum (python.org/~guido)



More information about the Python-ideas mailing list