python – How to set the current working directory?

The Question :

577 people think this question is useful

How to set the current working directory in Python?

The Question Comments :

The Answer 1

839 people think this answer is useful

Try os.chdir

os.chdir(path)

        Change the current working directory to path. Availability: Unix, Windows.

The Answer 2

136 people think this answer is useful

Perhaps this is what you are looking for:

import os
os.chdir(default_path)

The Answer 3

47 people think this answer is useful
import os
print os.getcwd()  # Prints the current working directory

To set the working directory:

os.chdir('c:\\Users\\uname\\desktop\\python')  # Provide the new path here

The Answer 4

11 people think this answer is useful

It work for Mac also

import os
path="/Users/HOME/Desktop/Addl Work/TimeSeries-Done"
os.chdir(path)

To check working directory

os.getcwd()

The Answer 5

-8 people think this answer is useful

people using pandas package

import os
import pandas as pd

tar = os.chdir('<dir path only>') # do not mention file name here
print os.getcwd()# to print the path name in CLI

the following syntax to be used to import the file in python CLI

dataset(*just a variable) = pd.read_csv('new.csv')

Add a Comment