Reputation: 83358
IPython provides handy object inspection tool, by writing object?
to REPL.
Can this be accessed in ipdb? It doesn't seem to be available as built-in command.
Currently I see the help gives out just the standard pdb help:
ipdb> help
Documented commands (type help <topic>):
========================================
EOF bt cont enable jump pdef psource run unt
a c continue exit l pdoc q s until
alias cl d h list pfile quit step up
args clear debug help n pinfo r tbreak w
b commands disable ignore next pinfo2 restart u whatis
break condition down j p pp return unalias where
Upvotes: 2
Views: 762
Reputation: 2673
Object inspection in the IPython shell prints the docstring and other information. The ipdb debugger can print the docstring, which is part of what IPython object inspection is doing. Just type
ipdb> print(object.__doc__)
For example, to inspect the built-in sum function
ipdb> print(sum.__doc__)
sum(iterable[, start]) -> value
Return the sum of an iterable of numbers (NOT strings) plus the value
of parameter 'start' (which defaults to 0). When the iterable is
empty, return start.
ipdb>
This is most of the way to what happens in the IPython shell
In [5]: sum?
Docstring:
sum(iterable[, start]) -> value
Return the sum of an iterable of numbers (NOT strings) plus the value
of parameter 'start' (which defaults to 0). When the iterable is
empty, return start.
Type: builtin_function_or_method
In [6]:
Another alternative is to just embed an IPython shell as a debug breakpoint. This is nice but I've not found a way to cleanly exit when such a debug breakpoint is embedded in a loop.
from IPython import embed
embed() # debug breakpoint
An even better approach that I just learned about is to use ! in ipdb, then things work the same as in the IPython shell.
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.
ipdb>
Upvotes: 2