[英]How do you pass script arguments to pdb (Python)?
I've got python script (ala #! /usr/bin/python) and I want to debug it with pdb.我有 python 脚本(ala #!/usr/bin/python),我想用 pdb 调试它。 How can I pass arguments to the script?
如何将参数传递给脚本?
I have a python script and would like to debug it with pdb.我有一个 python 脚本,想用 pdb 调试它。 Is there a way that I can pass arguments to the scripts?
有没有办法可以将参数传递给脚本?
python -m pdb myscript.py arg1 arg2 ...
This invokes pdb
as a script to debug another script.这将调用
pdb
作为脚本来调试另一个脚本。 You can pass command-line arguments after the script name.您可以在脚本名称后传递命令行参数。 See the pdb doc page for more details.
有关更多详细信息,请参阅pdb 文档页面。
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
python3 -m pdb myscript.py -a val
如果使用带有标志“a”和值“val”的 argparse
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.