how to go back to previous directory in python code example Example: get the previous working directory in python path = os.path.dirname(__file__) print(path)