Interpreter-like help in cmd.Cmd

Is there a way to get help the way you get it from the Python
interpreter (eg, 'help(dir)' gives help on the 'dir' command) in the
module cmd.Cmd? I know how to add commands and help text to cmd.Cmd
but I would also like to get the man-page-like help for classes and
functions. Does anyone know how to do that? Thanks.

Advertisements

Sarir Khamsi wrote:
> Is there a way to get help the way you get it from the Python
> interpreter (eg, 'help(dir)' gives help on the 'dir' command) in the
> module cmd.Cmd? I know how to add commands and help text to cmd.Cmd
> but I would also like to get the man-page-like help for classes and
> functions. Does anyone know how to do that? Thanks.
>>> dir(help)
['__call__', '__class__', '__delattr__', '__dict__', ...

I can't say exactly. That might depend on what you are doing with it,
and how you are currently handling other things with it. All I know is
that the builtin "help" just passes its arguments to pydoc.help() and
that seems to do the job.

I'd suggest you work from there and experiment with your current cmd.Cmd
mechanisms to see what you can get working, then post a snippet or to
back here for further assistance. Almost working code is almost always
better than starting with nothing. (I would help if I remembered
anything about cmd.Cmd, really, but it's been years.)

"""
All subclasses of Cmd inherit a predefined do_help().
This method, called with an argument 'bar', invokes
the corresponding method help_bar().

With no argument, do_help() lists all available help topics
(that is, all commands with corresponding help_*() methods),
and also lists any undocumented commands.
"""

This suggests that typing "help xxx" might call do_help('xxx')
and that will call help_xxx if it exists. So if you want help
on a non-cmd.Cmd command, you might want to modify do_help to
call pydoc as above instead of generating its default
have-no-help repsonse, whatever that is.

Just guessing, but that should get you closer.

You can look at the source in <wherever>python<versionstuff>\Lib\cmd.py
E.g.,
D:\Python23\Lib\cmd.py
or
D:\Python-2.4b1\Lib\cmd.py
for me.

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!