This is a stand-in for Sage’s inspection code in

sage.misc.sageinspect. If Sage is available, that code will be used here. Otherwise, use simple-minded replacements based on Python’s inspect module.


  • John Palmieri, Simon King
sagenb.misc.sageinspect.sagenb_getdef(obj, obj_name='')

Return the definition header for any callable object.


  • obj - function
  • obj_name - string (optional, default ‘’)

This calls inspect.getargspec, formats the result, and prepends obj_name.


sage: from sagenb.misc.sageinspect import sagenb_getdef
sage: def f(a, b=0, *args, **kwds): pass
sage: sagenb_getdef(f, 'hello')
'hello(a, b=0, *args, **kwds)'
sagenb.misc.sageinspect.sagenb_getdoc(obj, obj_name='')

Return the docstring associated to obj as a string. This is essentially a front end for inspect.getdoc.

INPUT: obj, a function, module, etc.: something with a docstring. If “self” is present in the docmentation, then replace it with \(obj_name\).


sage: from sagenb.misc.sageinspect import sagenb_getdoc
sage: sagenb_getdoc(sagenb.misc.sageinspect.sagenb_getdoc)[0:55]
'Return the docstring associated to ``obj`` as a string.'

Previous topic

Sage Notebook Introspection

Next topic

Process docstrings with Sphinx

This Page