python - ipdb 调试器中的 IPython 帮助功能

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

最佳答案

看起来你可以用 !(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/

相关文章:

python - 在Jupyter notebook中,如何安排子程序才能高效地编写项目?

python - 重置 ipython 内核

Python数组3D转视频

python - 检查是否从R安装了Python

ios - 我应该将 'Strip Debug Symbols During Copy' 和 'Strip Linked Produts' 与 Google Analytics 一起使用吗?

c# - 从 C++ Win32 调试托管组件

Python - 将 XLSX 转换为 PDF

python - 除了在尝试了try block 和程序的其余部分之后总是抛出 block 之外?

visual-studio - 从 Visual Studio 调试器获取变量

ipython - %precision 不尊重 IPython