-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"chdir" Contex manager for pathlib #69811
Comments
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. |
I'm not a Python core developer, but a few thoughts:
|
I did not know about cwd for Popen. It seems like the better way to go. 2015-11-14 19:58 GMT+01:00 desbma <report@bugs.python.org>:
|
What's the relation with subprocess.Popen ? |
I agree with desbma. |
In the context of subprocesses there is better way to run a program in specified working directory that temporary change current working directory in parent process. |
Ok, haven't read the last line of the description. thanks for the
|
So moving way from subprocess.Process; what about having this for other use cases? I know there is no thread-safe way to get this working, given it's a process state variable. However, can we have it as a non-thread-safe feature? |
Thanks for perservering, Filipe! ✨ 🍰 ✨ Per Steering Council decision, the context manager is approved: python/steering-council#77 |
There is renewed discussion on python-dev about placing this in contextlib. |
Can you share the link? I haven't seen anything recent. Is it under other thread? |
On 15Nov2021 01:04, Python Bug Reports <report@bugs.python.org> wrote:
It's in the discuss-ideas part of discuss.python.org during a
and I'm with Inada-san here: I think shutil is a better fit for both the |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: