Backport of contextlib.chdir stdlib class added in Python3.11.
Backport of contextlib.chdir
stdlib class added in Python3.11.
pip install contextlib-chdir
import os
import tempfile
from contextlib_chdir import chdir as chdir_ctx
with chdir_ctx(tempfile.gettempdir()):
print(os.getcwd()) # /tmp
You'll probably want to migrate to contextlib2
when
this change is included.