如何将脚本参数传递给 pdb (Python)?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/873089/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do you pass script arguments to pdb (Python)?
提问by Ayman Hourieh
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 调试它。有没有办法将参数传递给脚本?
回答by Ayman Hourieh
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 pagefor more details.
这将pdb
作为脚本调用以调试另一个脚本。您可以在脚本名称后传递命令行参数。有关更多详细信息,请参阅pdb 文档页面。
回答by Thomas
usually I use ipython
通常我使用 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
回答by JoErNanO
If, like me, you prefer the more graphical pudbdebugger, 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