Dynamic Object Introspection
IPython can inspect any object at runtime: its type, its methods, its documentation, and its source code - no debugger required. Tab completion, question marks, and the built-in help machinery turn the prompt into an interactive explorer for unfamiliar libraries.
Question Marks
import numpy as np
np? # quick doc: name, type, signature, short description
np.linalg? # doc for a module
np.linalg.solve?? # double question mark: full docstring
Who Am I - %who, %whos
a = 1
df = "some frame"
%who
%whos # adds type and size for each variable
%pinfo - Detailed Inspection
%pinfo np.linalg.solve
# shows: type, module, docstring, source file, calling signature
%get_ipython and Source
%pinfo -s np.array # source of the object, if available
import inspect
print(inspect.signature(np.linalg.solve))
dir, help, and type
print([m for m in dir(np) if "sort" in m])
help(np.sort)
print(type(np.array([1, 2])))
A Workflow for New Libraries
- import the package, then %whos to see what you have loaded.
- package? for the overview docstring.
- package.module? to drill into submodules.
- function?? for the full docstring, including examples.
- Tab completion to autocomplete attribute names as you type.
Summary
Use ? and ?? for instant documentation, %who/%whos to list your variables, %pinfo for detailed object inspection including source, and dir/help/type for the standard introspection tools. This interactive loop - import, explore, drill in - is how you learn any library without leaving the prompt.