如何将脚本参数传递给 pdb (Python)?
我有 python 脚本(ala #!/usr/bin/python),我想用 pdb 调试它。 如何将参数传递给脚本?
我有一个 python 脚本,想用 pdb 对其进行调试。 有没有办法可以将参数传递给脚本?
I've got python script (ala #! /usr/bin/python) and I want to debug it with pdb. How can I pass arguments to the script?
I have a python script and would like to debug it with pdb. Is there a way that I can pass arguments to the scripts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这将调用
pdb
作为脚本来调试另一个脚本。 您可以在脚本名称之后传递命令行参数。 有关更多详细信息,请参阅 pdb 文档页面。This invokes
pdb
as a script to debug another script. You can pass command-line arguments after the script name. See the pdb doc page for more details.通常我使用 ipython
usually I use ipython
python3 -m pdb myscript.py -a val
如果使用带有标志“a”和值“val”的argparsepython3 -m pdb myscript.py -a val
if using argparse with flag "a" and value "val"如果像我一样,您更喜欢图形化的 pudb 调试器,您可以传递脚本的参数直接通过这样做:
确实,调用:
不会工作将返回以下错误:
If, like me, you prefer the more graphical pudb debugger, you can pass the arguments of your script directly by doing:
Indeed, invoking:
won't work will return with the following error: