Runtime Inspection Modules
pydoc
Generates documentation from Python objects and their docstrings. render_doc returns a formatted text description; help uses related machinery. Documenting a module by name may import it and execute its top-level code, so inspect only trusted modules. This example documents an already defined function.
Formal Syntax & Structure
python syntaxpython
import pydocReturn Value
module
Module namespace available through import; import is a statement, not a value-returning expression.
Working Example
Example Snippetpython
import pydocdef convert(value): """Convert a value to text.""" return str(value)text = pydoc.render_doc(convert, renderer=pydoc.plaintext)print("Convert a value to text." in text)