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系统是集成的。

相关推荐
kexnjdcncnxjs7 小时前
HTML 中使用 EXIF.js 读取图片元数据失败的常见原因与解决方案
jvm·数据库·python
iuvtsrt7 小时前
Python如何实现定时异步任务_结合asyncio与loop.call_later调用
jvm·数据库·python
m0_463672207 小时前
HTML怎么标注成就连续打卡中断_HTML“断连,重新开始”提示【方法】
jvm·数据库·python
m0_596749097 小时前
CSS如何解决IE下按钮点击反馈缺失_使用active伪类前缀处理
jvm·数据库·python
iAm_Ike7 小时前
Python处理分类不平衡问题_使用平衡随机森林提升召回率
jvm·数据库·python
shimly1234567 小时前
vscode 很难删除 copilot,如何关闭 copilot 功能?
ide·vscode·copilot
毋语天7 小时前
Python 常用内置模块详解:日志、随机数、时间、OS 与 JSON
开发语言·python
右耳朵猫AI7 小时前
Python技术周刊 2026年第14周
开发语言·python·okhttp
2501_901200537 小时前
MongoDB事务会产生多少性能损耗
jvm·数据库·python
zh1570237 小时前
CSS如何通过Sass循环生成辅助类_批量创建颜色或间距样式
jvm·数据库·python