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

相关推荐
matlabgoodboy10 小时前
程序代做python代编程matlab定制代码编写C++代写plc设计java帮做
c++·python·matlab
副露のmagic10 小时前
更弱智的算法学习 day34
python·学习
AllFiles10 小时前
用Python turtle画出标准五星红旗,原来国旗绘制有这么多数学奥秘!
python
亲爱的非洲野猪10 小时前
Java线程池深度解析:从原理到最佳实践
java·网络·python
用户13779404999311 小时前
基于遗传算法实现自动泊车+pygame可视化
python
4***175411 小时前
强化学习中的蒙特卡洛方法
python
pen-ai11 小时前
打通 Python 与 C++ 的参数传递机制
开发语言·c++·python
至此流年莫相忘11 小时前
Python之深拷贝和浅拷贝
python
像风一样自由202011 小时前
XGBoost、LightGBM、CatBoost 原理深度剖析与全面对比
python
用户2308266766511 小时前
Python的管道符(|)联合类型语法糖
python