utils.py 323 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
"""This module offers some utils for code management"""
from contextlib import contextmanager
import os


@contextmanager
def cd(newdir):
    """Changes the directory inside a 'with' context"""
    prevdir = os.getcwd()
    os.chdir(os.path.expanduser(newdir))
    try:
        yield
    finally:
        os.chdir(prevdir)