如何更改运行调试的目录

时间:2019-06-26 13:22:41

标签: python visual-studio-code vscode-settings

我正在通过Visual Studio Code调试代码,但它不会根据脚本的位置更改路径。

我在Visual Studio Code中使用WSL,并且已将设置"python.terminal.executeInFileDir"更改为true,以确保当我调用文件时,它是相对于我所使用的脚本而不是脚本在我打开VS Code的目录中(一个Github存储库)。例如,我需要调用一个名为settings.json的文件,该文件位于我需要运行的脚本上方的一个文件夹中,因此我在脚本本身中运行

with open('../settings.json') as f: 
    settings = json.load(f)

在调试时,我需要运行

with open('settings.json') as f: 
    settings = json.load(f)

一个例子

try:
    with open('settings.json') as f: 
        settings = json.load(f)
except Exception as e:
    pass

try:
    with open('../settings.json') as f: 
        settings = json.load(f)
except Exception as e:
    pass

我希望调试能够以与脚本完全相同的方式运行。请帮助解决此问题。

0 个答案:

没有答案
相关问题