Help is available in a standard IPython shell via the help command or by using the ? character. For example, for help on the built-in sum function, either of the below commands in an IPython shell could be used.
In [1]: help(sum)
Help on built-in function sum in module builtin:
...
In [2]: sum?
Signature: sum(iterable, start=0, /)
Docstring: ...
I want to have the same functionality in an ipdb debugger. One enters an ipdb debugger by placing the below code at the location for a debug breakpoint.
from ipdb import set_trace
set_trace()
However, once inside the ipdb debugger the Help functions no longer work.
ipdb> help(sum)
*** No help for '(sum)'
ipdb> sum?
*** SyntaxError: invalid syntax
ipdb>
Help in IPython shell and ipdb debugger
The below command represents a way to print a docstring inside the ipdb debugger, however this is not exactly the same functionality as help(sum) and sum? in the IPython shell.
ipdb> print(sum.__doc__)
How then do I get the same help functionality in an ipdb debugger that exists in the IPython shell?
It looks like you can preface it with a !
(which is short for 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)