我几天前刚刚开始使用 VSCode,并决定尝试将它用于 Python。快速的谷歌搜索告诉我,launch.json 文件是你指定命令行参数的地方,但在它的生命周期中,我无法让它工作。看起来好像 launch.json 被完全忽略了。
这是我制作的一个准系统程序:
import sys
print("testing command line args")
print(sys.argv)
这是我的 launch.json 文件的样子。这几乎就是编辑器生成的内容,我只是添加了 args 参数:
{
// 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",
"justMyCode": true,
"args": ["arg1", "arg2"]
}
]
}
这是输出:
testing command line args
['d:\\Dev\\Python Projects\\test.py']
PS D:\Dev>
我竟然在各种 launch.json 参数中添加了乱码。这一切都只是被忽视而已。我到底做错了什么?