I want to grab the docstring in my commandline application, but every time I call the builtin help() function, Python goes into interactive mode.
How do I get the docstring of an object and not have Python grab focus?
I want to grab the docstring in my commandline application, but every time I call the builtin help() function, Python goes into interactive mode.
How do I get the docstring of an object and not have Python grab focus?
Any docstring is available through the .__doc__
property:
>>> print str.__doc__
In python 3, you'll need parenthesis for printing:
>>> print(str.__doc__)
You can use dir(
{insert class name here})
to get the contents of a class and then iterate over it, looking for methods or other stuff. This example looks in a class Task
for methods starting with the name cmd
and gets their docstring:
command_help = dict()
for key in dir( Task ):
if key.startswith( 'cmd' ):
command_help[ key ] = getattr( Task, key ).__doc__