【问题标题】:VS Code debug python script configuration ignores args attributeVS Code 调试 python 脚本配置忽略 args 属性
【发布时间】:2020-02-14 02:45:57
【问题描述】:

我正在尝试调试我编写的需要命令行参数但没有成功的 python3 脚本。我在搜索 stackoverflow 时找到了VSCode: How debug Python script with arguments,它指出属性 args 应该设置为参数列表。但是,当我运行我为调试 ./scripts 下的脚本而创建的调试配置时,我得到了 argparse 错误the following arguments are required: database, media_url, images. 我不确定我忽略了什么

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Populate Database Script Debug",
            "type": "python",
            "request": "launch",
            "program": "${workspaceFolder}/scripts/populate_sqlite.py",
            "console": "integratedTerminal",
            "args": ["db.sqlite3", "../tarot_juicer/static/img", "~/slipsnip/automation/tarot/out"],
            "cwd": "${workspaceFolder}/scripts/"
        }
    ]
}

在使用 vscode 调试 python 的同一主题上,我还注意到,当我的 populate_sqlite.py 脚本尝试读取与脚本存在于同一目录中的文件 data.csv 时,我得到 FileNotFoundError: [Errno 2] File data.csv does not exist: 'data.csv' 但是如果在终端我在运行调试配置之前导航到脚本目录,虽然我仍然遇到这个问题的主题问题,但这个问题已经解决了,为什么忽略 args?

如果有人能解释如何解决我的参数在调试执行时没有传递给脚本的问题,那将不胜感激。如果有人也可以引导我朝着正确的方向前进,我如何才能在 cwd 中存在文件而不必 cd 进入脚本目录,这也将不胜感激。谢谢。

【问题讨论】:

    标签: python-3.x visual-studio-code vscode-debugger


    【解决方案1】:

    它似乎已经更正了,今天重启后又回到了项目中。可能需要重新启动vscode,问题已经消失,现在正在传递args。

    【讨论】:

    • 我刚刚在 Visual Sudio Code v1.60 中使用 remote-ssh 到 Mac 进行开发时遇到了这种确切的行为。
    • 谢谢你!我不必重新启动(我在 Mac 上),但我确实退出并重新启动 VS Code,突然间,就像变魔术一样,我的 args 开始出现。跨度>
    猜你喜欢
    • 2021-06-20
    • 2017-07-20
    • 2020-09-11
    • 2018-02-20
    • 2018-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多