如何设置当前工作目录?

发布于 2024-08-12 10:45:26 字数 26 浏览 4 评论 0原文

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

How to set the current working directory in Python?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

如痴如狂 2024-08-19 10:45:26

尝试 os.chdir

导入操作系统
os.chdir(路径)

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

Try os.chdir

import os
os.chdir(path)

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

凑诗 2024-08-19 10:45:26

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

import os
os.chdir(default_path)

Perhaps this is what you are looking for:

import os
os.chdir(default_path)
醉城メ夜风 2024-08-19 10:45:26
import os
print os.getcwd()  # Prints the current working directory

设置工作目录:

os.chdir('c:\\Users\\uname\\desktop\\python')  # Provide the new path here
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
独自←快乐 2024-08-19 10:45:26

它也适用于 Mac

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

检查工作目录

os.getcwd()

It work for Mac also

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

To check working directory

os.getcwd()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文