In Python the working directory can be changed by following way:-
When the current working directory in a subprocess changed it does not change the current working directory in the parent process.
Another way it can be done by using contextmanager:-
Context managers in Python facilitate the proper handling of resources like file operations or database connections.
from contextlib import contextmanager
owd = os.getcwd()
To know more about this you can have a look at the following video tutorial:-