<p>似乎您希望使用VS代码调试器运行python文件,但无法告诉它启动程序所使用的参数</p>
<p>导航到debugger选项卡(Ctrl/Cmd+Shift+D)并单击“创建一个launch.json文件”,在出现的提示中指定要向python文件添加启动配置</p>
<p><a href="https://i.stack.imgur.com/L6eKX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/L6eKX.png" alt="Screenshot to create a launch.json file"/></a></p>
<p>它应该创建并打开一个样板json文件。在<code>"configurations"</code>的第一个元素中,您可以添加一个键<code>"args"</code>,其中包含数组中所有必需的参数</p>
<p>完整地说,json文件可能如下所示:</p>
<pre class="lang-js prettyprint-override"><code>{
// 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",
// this is what I added manually
"args": [
"a.txt",
"b.txt",
"out.png"
]
}
]
}
</code></pre>
<p>然后,打开python文件后,通过debug选项卡或右上角的绿色箭头启动它</p>
<p>编辑:</p>
<p>通过频繁更改命令行参数,您可以告诉VS代码<a href="https://github.com/microsoft/vscode-node-debug/issues/108#issuecomment-581815593" rel="nofollow noreferrer">prompt</a>您这些参数。请参阅下面的json。如果你有什么不明白的,告诉我</p>
<pre class="lang-js prettyprint-override"><code>{
// 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",
"args": [
"${input:firstArg}",
"${input:secondArg}",
"out.png"
]
}
],
"inputs": [
{
"id": "firstArg",
"type": "promptString",
"default": "myDefault.txt",
"description": "First txt"
},
{
"id": "secondArg",
"type": "promptString",
"description": "Now your second txt"
}
]
}
</code></pre>