blob: fad9adebf67c6c580c7d8d995c8b07e02793256b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
import os
class changedir:
"""Context manager for changing the current working directory"""
def __init__(self, newPath):
self.newPath = os.path.expanduser(newPath)
def __enter__(self):
self.savedPath = os.getcwd()
os.chdir(self.newPath)
def __exit__(self, etype, value, traceback):
os.chdir(self.savedPath)
|