这个问题在这里已经有答案了:

如何在Python中设置当前工作目录?

有帮助吗?

解决方案

尝试 os.chdir

os.chdir(path)

将当前工作目录更改为路径。可用性:Unix、Windows。

其他提示

也许这就是您正在寻找的:

import os
os.chdir(default_path)
import os
print os.getcwd()  # Prints the current working directory

设置工作目录:

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

它适用于 苹果

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

检查工作目录

os.getcwd()

使用...

import os
os.chdir(path)

其中 (path) 的格式为...的输出所示

os.getcwd()

使用 pandas 包的人

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

以下语法用于在 python CLI 中导入文件

dataset(*just a variable) = pd.read_csv('new.csv')

您需要导入 os 模块,然后您可以使用 chdir() 方法,但不要忘记使用引号('') 括号内:

import os

os.chdir('default_path')
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top