![](/img/trans.png)
[英]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.