Get and Set Working Directory in Python

we will learn how to set working directory in python. We will also learn to get the current working directory in Python. Let’s discuss how to get and set working directory in python with an example for each.

Get Current Working directory in python:

import os
os.getcwd()

The above code gets the current working directory so the output will be

D:\Public\R SAS PGSQL\Python\Python Tutorial\

 

Set working directory in python:

import os
os.chdir("D:\\Public\\Python\\")

or

import os
os.chdir("D:/Public/Python/")

So the working directory will be set to the above mentioned path.

 

                                                                                                           Get and Set Working Directory in Python next

Author

  • Sridhar Venkatachalam

    With close to 10 years on Experience in data science and machine learning Have extensively worked on programming languages like R, Python (Pandas), SAS, Pyspark.