如何设置当前工作目录?

705 投票
4 回答
1121897 浏览
提问于 2025-04-15 16:28

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

4 个回答

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

要设置工作目录:

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

也许这就是你在找的东西:

import os
os.chdir(default_path)
1015

试试 os.chdir

import os
os.chdir(path)

        把当前的工作目录改成你指定的路径。这个功能在Unix和Windows系统上都可以用。

撰写回答