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

相关推荐
PythonFun17 分钟前
Python批量下载PPT模块并实现自动解压
开发语言·python·powerpoint
炼丹师小米1 小时前
Ubuntu24.04.1系统下VideoMamba环境配置
python·环境配置·videomamba
GFCGUO1 小时前
ubuntu18.04运行OpenPCDet出现的问题
linux·python·学习·ubuntu·conda·pip
985小水博一枚呀2 小时前
【深度学习基础模型】神经图灵机(Neural Turing Machines, NTM)详细理解并附实现代码。
人工智能·python·rnn·深度学习·lstm·ntm
萧鼎4 小时前
Python调试技巧:高效定位与修复问题
服务器·开发语言·python
IFTICing4 小时前
【文献阅读】Attention Bottlenecks for Multimodal Fusion
人工智能·pytorch·python·神经网络·学习·模态融合
大神薯条老师4 小时前
Python从入门到高手4.3节-掌握跳转控制语句
后端·爬虫·python·深度学习·机器学习·数据分析
程序员爱德华4 小时前
Python环境安装教程
python
huanxiangcoco4 小时前
152. 乘积最大子数组
python·leetcode
萧鼎5 小时前
Python常见问题解答:从基础到进阶
开发语言·python·ajax