How to set the current working directory?

PythonWorking Directory

Python Problem Overview


How to set the current working directory in Python?

Python Solutions


Solution 1 - Python

Try os.chdir

> os.chdir(path) >         Change the current working directory to path. Availability: Unix, Windows.

Solution 2 - Python

Perhaps this is what you are looking for:

import os
os.chdir(default_path)

Solution 3 - Python

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

Solution 4 - Python

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 - Python

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionricardoView Question on Stackoverflow
Solution 1 - PythonMark ByersView Answer on Stackoverflow
Solution 2 - PythonunutbuView Answer on Stackoverflow
Solution 3 - PythondineshView Answer on Stackoverflow
Solution 4 - PythonPritamJView Answer on Stackoverflow
Solution 5 - Pythonuser3521180View Answer on Stackoverflow