[New-bugs-announce] [issue25625] "chdir" Contex manager for pathlib

Jáchym Barvínek report at bugs.python.org
Sat Nov 14 12:45:43 EST 2015


New submission from Jáchym Barvínek:

I use this context manager in my code:

@contextmanager
def in_directory(path):
    pwd = str(Path().absolute())
    if not path.is_dir():
        path = path.parent
    os.chdir(str(path))
    yield path.absolute()
    os.chdir(pwd)

I thought it would be nice to have something like this in the pathlib as a method of Path library, I find it quite convenient, especially when dealing with subprocesses.

----------
components: Library (Lib)
messages: 254664
nosy: Jáchym Barvínek
priority: normal
severity: normal
status: open
title: "chdir" Contex manager for pathlib
type: enhancement
versions: Python 3.5

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


More information about the New-bugs-announce mailing list