[英]How to debug a Python module in Visual Studio Code's launch.json
[英]Visual Studio Code Python, determine in launch.json which module is started
我正在使用Visual Studio Code在python中编程。 当前,当在每个模块上按F5
键时,我想使用不同的参数来启动两个可运行模块。
我以以下方式指定了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: Aktuelle Datei",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/Simulation.py",
"console": "integratedTerminal",
"args": ["-iTestInput"]
}
]
}
我启动的每个模块都传递了-iTestInput
参数,因此在那之前一切都很好。
现在,我想为不同的模块指定两个配置,因此添加了第二个配置,并希望指定应在其上使用config的程序:
{
// 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: Aktuelle Datei",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/Simulation.py",
"console": "integratedTerminal",
"args": ["-iSimulation"]
},
{
"name": "Python: Aktuelle Datei",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/ConvertToData.py",
"console": "integratedTerminal",
"args": ["-iinput"]
}
]
}
因此,我想在启动Simulation.py
时传递-iSimulation
参数,而在启动ConvertToData.py
时传递-iinput
。
但是现在,每次Simulation.py
以指定的参数开头。 我知道为什么会这样(因为我直接指定了名称,这是第一个配置)。 我希望我的launch.json
区分我启动的模块。
有人可以帮忙吗?
您的启动配置的名称是相同的
试试这个launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Simulation",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/Simulation.py",
"console": "integratedTerminal",
"args": ["-iSimulation"]
},
{
"name": "Python: ConvertToData",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/ConvertToData.py",
"console": "integratedTerminal",
"args": ["-iinput"]
}
]
}
从“调试”选项卡上的组合框中选择所需的一个,然后按F5
使用扩展命令变量 (v0.5.0),您可以使用单个启动配置
{ "version": "2.0.0", "tasks": [ { "name": "Python: Current File", "type": "python", "request": "launch", "program": "${file}", "console": "integratedTerminal", "args" : ["${input:chooseArgs}"] } ], "inputs": [ { "id": "chooseArgs", "type": "command", "command": "extension.commandvariable.file.fileAsKey", "args": { "Simulation.py": "-iSimulation", "ConvertToData.py": "-iinput" } } ] }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.