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\\")
import os os.chdir("D:/Public/Python/")
So the working directory will be set to the above mentioned path.