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

时间:2021-12-13 07:13:16

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?

我有python脚本(ala#!/ usr / bin / python),我想用pdb调试它。如何将参数传递给脚本?

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?

我有一个python脚本,想用pdb调试它。有没有办法可以将参数传递给脚本?

2 个解决方案

#1


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.

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

#2


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

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

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

#1


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.

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

#2


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

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

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