在VSCODE Python中更改工作目录的问题

发布于 2025-01-28 06:04:16 字数 453 浏览 2 评论 0原文

一直在尝试更改VSCODE中的工作目录。 我的环境是基本的Anaconda环境。

import os

os.getcwd()

>>> '/Users/hh'

然后,我将其更改为,

os.chdir('/Users/hh/pywd/')

os.getcwd()

>>> '/Users/hh/pywd/'

但是当我关闭时,重新启动VSCODE并运行

import os

os.getcwd()
## I get the output below yet again

>>> '/Users/hh'

WD设置为先前的状态。

这很好奇,因为我与Spyder或Jupyterlab没有同样的问题。

感谢您的帮助。

Been trying to change my working directory in VScode.
My environment is the base Anaconda environment.

import os

os.getcwd()

>>> '/Users/hh'

I then change it to

os.chdir('/Users/hh/pywd/')

os.getcwd()

>>> '/Users/hh/pywd/'

But when I close down, restart VScode and run

import os

os.getcwd()
## I get the output below yet again

>>> '/Users/hh'

The wd is set to its previous state.

This is rather curious as I don't have the same issue with Spyder or JupyterLab.

Thankful for help.

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

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

发布评论

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

评论(1

假装不在乎 2025-02-04 06:04:16

VSCODE的路径基于工作区所在的目录。

关闭VSCODE时,它将自动返回工作区目录,而不是在上次运行结束时呆在州。

尽管您目前还还原代码,但您将无法获得最后一次运行的结果。

这也是有益的,可以确保在搜索路径时不会混淆VScode。

The path of vscode is based on the directory where the workspace is located.

When you close vscode , it will automatically return to the workspace directory instead of staying in the state at the end of the last run.

Although you restore the code at this time, you will not get the result of the last run.

This is also beneficial, which can ensure that the vscode will not be confused when searching path.

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