我正在使用vscode编写Python,当我运行.py文件时,它们是从工作区的目录中运行的。
如何从文件dricetory而不是工作区目录中运行该文件?
我尝试将其设置为:python.terminal.executeInFileDir
,但设置没有任何改变。在https://code.visualstudio.com/docs/python/settings-reference上,他们对此的解释正是我要尝试做的,但没有用。
我还尝试了launch.json中的几个不同变量,例如"cwd": "{$fileDirname}
,"cwd": "{$file}
,"cwd": "{$fileDirname}
。
我的launch.json:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"cwd": "{$fileDirname}"
}
]
}