【发布时间】: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