Source code for whisk.cd

import os

[docs]class cd: """ Context manager for changing the current working directory Based on https://stackoverflow.com/questions/431684/how-do-i-change-the-working-directory-in-python/13197763#13197763 """ def __init__(self, newPath): self.newPath = os.path.expanduser(newPath)
[docs] def __enter__(self): self.savedPath = os.getcwd() os.chdir(self.newPath)
[docs] def __exit__(self, etype, value, traceback): os.chdir(self.savedPath)