Tutorial :How to set the current working directory?



Question:

How to set the current working directory in Python?


Solution:1

Try os.chdir

os.chdir(path)  

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


Solution:2

Perhaps this is what you are looking for:

import os  os.chdir(default_path)  


Solution:3

import os;  print os.getcwd(); # Prints the working directory  

To set the working directory:

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


Solution:4

It work for Mac also

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

To check working directory

os.getcwd()  


Solution: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')  


Solution:6

You need to import the os module and then you can use the chdir() method, but don't forget to use the quotations ('') inside the parenthesis:

import os    os.chdir('default_path')  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »