Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.26 KB | None | 0 0
  1. import os
  2. from contextlib import contextmanager
  3. from typing import Union, ContextManager
  4.  
  5. PathType = Union[os.PathLike, str]
  6.  
  7.  
  8. @contextmanager
  9. def cd(path: PathType) -> ContextManager[None]:
  10. old_path = Path.cwd()
  11. os.chdir(path)
  12. yield
  13. os.chdir(old_path)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement