How to set the current working directory? [duplicate]

此生再无相见时 提交于 2019-11-26 02:39:41

问题


How to set the current working directory in Python?


回答1:


Try os.chdir

os.chdir(path)

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




回答2:


Perhaps this is what you are looking for:

import os
os.chdir(default_path)



回答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



回答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()



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


来源:https://stackoverflow.com/questions/1810743/how-to-set-the-current-working-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!