通过 help 命令或使用 ? 字符可以在标准 IPython shell 中获得帮助。例如,要获得有关内置 sum 函数的帮助,可以使用 IPython shell 中的以下任一命令。
In [1]: help(sum)
Help on built-in function sum in module builtin:
...
In [2]: sum?
Signature: sum(iterable, start=0, /)
Docstring: ...
我想在 ipdb 调试器中拥有相同的功能。通过将以下代码放置在调试断点的位置,可以进入 ipdb 调试器。
from ipdb import set_trace
set_trace()
但是,一旦进入 ipdb 调试器,帮助功能就不再起作用。
ipdb> help(sum)
*** No help for '(sum)'
ipdb> sum?
*** SyntaxError: invalid syntax
ipdb>
Help in IPython shell and ipdb debugger
下面的命令代表了一种在 ipdb 调试器中打印文档字符串的方法,但是这与 help(sum) 和 sum 的功能并不完全相同? 在 IPython shell 中。
ipdb> print(sum.__doc__)
然后如何在 IPython shell 中的 ipdb 调试器中获得相同的帮助功能?
最佳答案
看起来你可以用 !
(exec
的缩写)作为开头
ipdb> !help(sum)
Help on built-in function sum in module builtins:
sum(iterable, start=0, /)
Return the sum of a 'start' value (default: 0) plus an iterable of numbers
When the iterable is empty, return the start value.
This function is intended specifically for use with numeric values and may
reject non-numeric types.
(END)
关于python - ipdb 调试器中的 IPython 帮助功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40476608/