vscode debug python launch.json添加args不起作用

问题

为了带入参数调试python 程序,按照网上搜到的教程配置了lauch.json文件,文件中添加了"args": "model" "0" "path"

json 复制代码
{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: 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":[ "****", "0", "*****" ]
        }
    ]
}

但是点击debug按钮,并没有读取到launch文件中的args参数,python中打印len(sys.argv)依然等于1。

原因

参考:vscode-python 中的 issues

vscode-doc: Python debugging in VS Code

简单来说就是:

1、界面右上角的debug按钮是一个扩展插件,是独立的debug系统,不读launch.json文件。所以在launch.json中的任何配置都不生效

2、F5/Run>Start Debugging,这两个选项都可以很好地与launch.json设置配合使用。

解决方案

1、按F5(或菜单栏Run->Start Debugging)

2、在launch.json里添加"purpose": "debug-in-terminal", 使用purpose注意事项

3、点击左侧debug窗口里面的debug按钮,它与debug系统是集成的。

相关推荐
copyer_xyf5 分钟前
Python 函数全面总结
前端·后端·python
zmzb01036 分钟前
Python课后习题训练记录Day123
开发语言·python
PersistJiao8 分钟前
python环境下免费、专业的中英翻译
开发语言·windows·python·机器翻译
高级打杂工程师-伍六六11 分钟前
想随时随地做点自己的事?创建一台VSCode登录的云电脑
人工智能·vscode
2023自学中21 分钟前
Linux虚拟机,VSCode + GDB 调试配置:launch.json 模板
linux·vscode·嵌入式
hujinyuan2016023 分钟前
中国电子学会青少年软件编程(Python)(二级)等级考试试卷-真题+答案(2026年3月)
python·机器人
老毛肚26 分钟前
记一次逆向
开发语言·python
维度攻城狮36 分钟前
vscode使用SSH远程控制时显示远程主机运行的软件界面
vscode·ssh
星恒随风40 分钟前
Python 基础语法详解(3):顺序语句、条件语句和循环语句一篇讲清楚
开发语言·笔记·python·学习