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

相关推荐
Dontla3 小时前
用pip install -e .开发Python包时,Python项目目录结构(项目结构)(可编辑安装editable install)
python·pip
Thomas.Sir3 小时前
第三章:Python3 之 字符串
开发语言·python·字符串·string
威联通网络存储4 小时前
告别掉帧与素材损毁:威联通 QuTS hero 如何重塑影视后期协同工作流
前端·网络·人工智能·python
Dxy12393102164 小时前
Python 根据列表中某字段排序:从基础到进阶
开发语言·windows·python
splage5 小时前
Java进阶——IO 流
java·开发语言·python
cliffordl5 小时前
设计模式(python)
python·设计模式
always_TT5 小时前
从Python_Java转学C语言需要注意什么?
java·c语言·python
2301_793804695 小时前
定时任务专家:Python Schedule库使用指南
jvm·数据库·python
Dontla6 小时前
VScode插件SQLite Viewer介绍(允许开发者不离开编辑器,直接打开、浏览和查询SQLite数据库文件)(ChromaDB、向量库插件、数据库插件、.sqlite3)DBeaver
数据库·vscode