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

相关推荐
@sinner2 小时前
你好,Scikit-learn:从零开始你的第一个机器学习项目
python·机器学习·scikit-learn
麦烤楽鸡翅2 小时前
简单迭代法求单根的近似值
java·c++·python·数据分析·c·数值分析
hyswl6662 小时前
2025年开发小程序公司推荐
python·小程序
独行soc3 小时前
2025年渗透测试面试题总结-258(题目+回答)
网络·python·安全·web安全·渗透测试·安全狮
程序员小远3 小时前
Appium-移动端自动测试框架详解
自动化测试·软件测试·python·测试工具·职场和发展·appium·测试用例
青瓷程序设计3 小时前
花朵识别系统【最新版】Python+TensorFlow+Vue3+Django+人工智能+深度学习+卷积神经网络算法
人工智能·python·深度学习
hyswl6664 小时前
2025年郑州开发小程序公司推荐
python·小程序
B站计算机毕业设计之家4 小时前
基于Python音乐推荐系统 数据分析可视化 协同过滤推荐算法 大数据(全套源码+文档)建议收藏✅
python·数据分析·推荐算法
用户785127814704 小时前
实战解析:淘宝/天猫商品描述API(taobao.item_get_desc)接口
python
codists4 小时前
Pycharm错误:JetBrains AI URL resolution failure
python