如何将脚本参数传递给 pdb (Python)?

发布于 2024-07-20 17:27:56 字数 128 浏览 7 评论 0原文

我有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

じ违心 2024-07-27 17:27:56
python -m pdb myscript.py arg1 arg2 ...

这将调用 pdb 作为脚本来调试另一个脚本。 您可以在脚本名称之后传递命令行参数。 有关更多详细信息,请参阅 pdb 文档页面

python -m pdb myscript.py arg1 arg2 ...

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.

赠佳期 2024-07-27 17:27:56

通常我使用 ipython


-i
    If running code from the command line, become interactive afterwards.
    It is often useful to follow this with `--` to treat remaining flags as
    script arguments.


ipython --pdb -i -- test.py -a

usually I use ipython


-i
    If running code from the command line, become interactive afterwards.
    It is often useful to follow this with `--` to treat remaining flags as
    script arguments.


ipython --pdb -i -- test.py -a
百思不得你姐 2024-07-27 17:27:56

python3 -m pdb myscript.py -a val 如果使用带有标志“a”和值“val”的argparse

python3 -m pdb myscript.py -a val if using argparse with flag "a" and value "val"

蓝眼泪 2024-07-27 17:27:56

如果像我一样,您更喜欢图形化的 pudb 调试器,您可以传递脚本的参数直接通过这样做:

pudb myscript.py arg1 arg2 ...

确实,调用:

 python -m pudb myscript.py arg1 arg2 ...

不会工作将返回以下错误:

No module named pudb.__main__; 'pudb' is a package and cannot be directly executed

If, like me, you prefer the more graphical pudb debugger, you can pass the arguments of your script directly by doing:

pudb myscript.py arg1 arg2 ...

Indeed, invoking:

 python -m pudb myscript.py arg1 arg2 ...

won't work will return with the following error:

No module named pudb.__main__; 'pudb' is a package and cannot be directly executed
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文