在 VS Code 中,我根本无法在 launch.json 中获取命令行参数。我做错了什么?

问题描述 投票:0回答:1

我几天前刚刚开始使用 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 参数中添加了乱码。这一切都只是被忽视而已。我到底做错了什么?

python visual-studio-code command-line command-line-arguments
1个回答
6
投票

配置完launch.json文件后,应该点击运行和调试中的运行按钮,而不是直接点击文件右上角的调试。

© www.soinside.com 2019 - 2024. All rights reserved.