CKTIS / Python
help()
Displays interactive documentation for a supplied object.
Version: Python 3.14; repository image, production runtime not attested
Syntax
help()
help(request)Displays interactive documentation for a supplied object.
Documentation output is written to a stream. Capturing it lets a program inspect a stable fact without depending on the full interpreter-specific layout.
The site-provided help utility sends documentation to the output stream. With the meters function it includes the function’s docstring. Capturing stdout and checking only that sentence yields True without depending on page layout. The call returns None; calling it with no argument starts interactive help.
from contextlib import redirect_stdout
from io import StringIO
def meters():
"""Convert distance into metres."""
out = StringIO()
with redirect_stdout(out):
assert help(request=meters) is None
assert meters.__doc__ in out.getvalue()
Examples
from contextlib import redirect_stdout
from io import StringIO
def meters():
"""Convert distance into metres."""
with redirect_stdout(StringIO()) as buffer:
help(meters)
print("Convert distance into metres." in buffer.getvalue())
Result
True
The site-provided help utility sends documentation to the output stream. With the meters function it includes the function’s docstring. Capturing stdout and checking only that sentence yields True without depending on page layout. The call returns None; calling it with no argument starts interactive help.