Amara Amara - 5 months ago 20
Python Question

How do I change directory back to my original working directory with Python?

I have a function that resembles the one below. I'm not sure how to use the os module to get back to my original working directory at the conclusion of the jar's execution.

def run():
owd = os.getcwd()
#first change dir to build_dir path
os.chdir(testDir)
#run jar from test directory
os.system(cmd)
#change dir back to original working directory (owd)


note: I think my code formatting is off - not sure why. My apologies in advance

Answer

You simply need to add the line:

os.chdir(owd)

Just a note this was also answered in your other question.

Comments