本文翻译自:How to set the current working directory? [duplicate]
This question already has an answer here: 这个问题在这里已有答案:
- How do I change directory (cd) in Python? 如何在Python中更改目录(cd)? 13 answers 13个答案
How to set the current working directory in Python? 如何在Python中设置当前工作目录?
#1楼
参考:https://stackoom.com/question/7b3X/如何设置当前工作目录-重复
#2楼
os.chdir(path)
Change the current working directory to path. 将当前工作目录更改为路径。 Availability: Unix, Windows. 可用性:Unix,Windows。
#3楼
Perhaps this is what you are looking for: 也许这就是你要找的东西:
import os
os.chdir(default_path)
#4楼
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
#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 以下语法用于在python CLI中导入文件
dataset(*just a variable) = pd.read_csv('new.csv')
#6楼
It work for Mac also 它也适用于Mac
import os
path="/Users/HOME/Desktop/Addl Work/TimeSeries-Done"
os.chdir(path)
To check working directory 检查工作目录
os.getcwd()