+1 vote
in Programming Languages by (64.7k points)
Is there any function to change the current working directory using Python? I want to do it programmatically instead of using Linux command.

1 Answer

+3 votes
by (15.9k points)
selected by
 
Best answer

You can use the "chdir()" function to change the current working directory in Python. This function is part of the "os" module.

import os

os.getcwd()      # current working directory

os.chdir('/new/working/directory')   # Change current working directory

In the above chdir() function, change directory with your directory.

 


...