ipdb调试器中的IPython帮助功能

时间:2016-11-07 23:38:34

标签: python debugging ipython ipdb

通过 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调试器中获得相同的帮助功能?

1 个答案:

答案 0 :(得分:3)

看起来您可以使用!exec的缩写)前言{/ p>

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)