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

相关推荐
CHANG_THE_WORLD9 分钟前
<Fluent Python > Unicode 文本与字节
开发语言·python
测试员周周10 分钟前
【AI测试系统】第1篇:LangGraph 实战:用 State Graph 搭建 AI测试流水线(4 步编排 + RAG 增强 + 完整代码)
linux·windows·python·功能测试·microsoft·单元测试·多轮对话
噜噜噜阿鲁~15 分钟前
python学习笔记 | 8.2、函数式编程-返回函数
笔记·python·学习
中二痞30 分钟前
下载Python 版本,环境变量变更以及PyCharm更换python版本
开发语言·python·pycharm
SilentSamsara33 分钟前
标准库精讲:collections/itertools/functools/pathlib 实战
开发语言·vscode·python·青少年编程·pycharm
小郑加油34 分钟前
python学习Day8-9天:函数(def)的基础运用
python·学习
2401_8242226934 分钟前
如何卸载并重装Oracle Grid_Deinstall脚本与ASM磁盘清理
jvm·数据库·python
qq_4142565737 分钟前
生产库如何利用Navicat实现配置特定触发器事件调度_提高管理效率
jvm·数据库·python
2301_7756398943 分钟前
mysql如何查看服务器支持的存储引擎_使用SHOW ENGINES命令
jvm·数据库·python
love530love44 分钟前
Python 3.12 解决 MediaPipe “no attribute ‘solutions‘” 终极方案:基于全版本硬核实测的避坑指南
开发语言·人工智能·windows·python·comfyui·mediapipe·solutions