How to set the current working directory? [duplicate]

Posted on

Question :

How to set the current working directory? [duplicate]

How to set the current working directory in Python?

Asked By: ricardo


Answer #1:

Try os.chdir


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

Answered By: Mark Byers

Answer #2:

Perhaps this is what you are looking for:

import os
Answered By: unutbu

Answer #3:

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
Answered By: dinesh

Answer #4:

It work for Mac also

import os
path="/Users/HOME/Desktop/Addl Work/TimeSeries-Done"

To check working directory

Answered By: PritamJ

Answer #5:

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')
Answered By: user3521180

Leave a Reply

Your email address will not be published. Required fields are marked *