Created
October 29, 2018 12:59
-
-
Save Tadaboody/978a4c6dcb073c7f02742a1357375cb8 to your computer and use it in GitHub Desktop.
Context manager to cd into a dir for a while
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from contextlib import contextmanager | |
@contextmanager | |
def cd(path: os.PathLike): | |
"""Context manager that sets the cwd to be `path`""" | |
old_path = os.getcwd() | |
os.chdir(path) | |
yield | |
os.chdir(old_path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment