VSCODE Python 将"当前文件"作为模块启动



我正在尝试找到一种方法将当前文件作为模块的参数。我在任何地方都找不到它,所以我正在尝试堆栈溢出

{
"name": "Python: Synapse",
"type": "python",
"request": "launch",
"module": "projFolder.targetModule",
"console": "integratedTerminal"
}

手动指定模块参数(如上面的示例(有效。但是想到为每个文件执行此操作,希望我将其自动化。我尝试过 ${file},但它给出的是文件路径而不是模块。所以它没有用。如何将当前当前文件作为模块启动?

ps:来自 https://stackoverflow.com/a/57416114/6088796 的答案,但我修改了一个垃圾

将这样的东西添加到您的launch.json中,但是如果您想运行多模块(在不同的地方,您可以做的唯一方法是使用多配置或使用插件(见下文(

"configurations": [
{
"name": "Python: Module",
"type": "python",
"request": "launch",
"module": "yourmodule.${fileBasenameNoExtension}",
"stopOnEntry": true
},

您可以使用扩展命令变量来获取此带有点分隔符的相对目录。

{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Module CmdVar",
"type": "python",
"request": "launch",
"console": "integratedTerminal",
"module": "${command:extension.commandvariable.file.relativeDirDots}.${fileBasenameNoExtension}",
}
]
}

最新更新