Skip to content

Instantly share code, notes, and snippets.

@CMCDragonkai
Created April 4, 2018 00:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CMCDragonkai/49b411a9da3169f26f78144608fd400a to your computer and use it in GitHub Desktop.
Save CMCDragonkai/49b411a9da3169f26f78144608fd400a to your computer and use it in GitHub Desktop.
With context for jumping the current working directory into a directory and jumping back #python
import os
import contextlib
@contextlib.contextmanager
def jumpdir(path):
old_dir = os.getcwd()
os.chdir(path)
try:
yield
finally:
os.chdir(old_dir)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment