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

相关推荐
sz-lcw1 天前
HOG特征向量计算方法
人工智能·python·算法
ZTLJQ1 天前
驾驭高并发:Python协程与 async/await 完全解析
服务器·数据库·python
一勺菠萝丶1 天前
芋道框架 - API 前缀区分机制
java·linux·python
kcuwu.1 天前
Python判断及循环
android·java·python
前进的李工1 天前
LangChain使用之Model IO(提示词模版之ChatPromptTemplate)
java·前端·人工智能·python·langchain·大模型
Fairy要carry1 天前
面试-Agent上下文过载、步骤混乱的问题
开发语言·python
2501_916007471 天前
在非 Xcode 环境下完成苹果开发编译的记录 iOS 编译与调试
ide·vscode·ios·cocoa·个人开发·xcode·敏捷流程
今儿敲了吗1 天前
python基础学习笔记第五章——容器
笔记·python·学习
qq_334903151 天前
使用Flask快速搭建轻量级Web应用
jvm·数据库·python
E_ICEBLUE1 天前
在 Python 中对比 Word 文档:自动生成修订报告
python·word