473,583 Members | 3,413 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.

Sarir
Jul 19 '05 #1
4 3339
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__', ...

[Hmm... unexpected result... let's see what it is.]
help.__class__

<class 'site._Helper'>

[ah... loading site.py and looking for "_Helper".. .]
class _Helper(object) :
"""Define the built-in 'help'.
This is a wrapper around pydoc.help (with a twist).

"""

def __repr__(self):
return "Type help() for interactive help, " \
"or help(object) for help about object."
def __call__(self, *args, **kwds):
import pydoc
return pydoc.help(*arg s, **kwds)
HTH :-)

-Peter
Jul 19 '05 #2
Peter Hansen <pe***@engcorp. com> writes:
class _Helper(object) :
"""Define the built-in 'help'.
This is a wrapper around pydoc.help (with a twist).

"""

def __repr__(self):
return "Type help() for interactive help, " \
"or help(object) for help about object."
def __call__(self, *args, **kwds):
import pydoc
return pydoc.help(*arg s, **kwds)


Thanks, but how do I integrate this with cmd.Cmd?
Jul 19 '05 #3
Sarir Khamsi wrote:
Peter Hansen <pe***@engcorp. com> writes:
class _Helper(object) : .... def __call__(self, *args, **kwds):
import pydoc
return pydoc.help(*arg s, **kwds)


Thanks, but how do I integrate this with cmd.Cmd?


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.)

-Peter
Jul 19 '05 #4
On Thu, 09 Jun 2005 16:53:17 -0700, Sarir Khamsi <sa**********@r aytheon.com> wrote:
Peter Hansen <pe***@engcorp. com> writes:
class _Helper(object) :
"""Define the built-in 'help'.
This is a wrapper around pydoc.help (with a twist).

"""

def __repr__(self):
return "Type help() for interactive help, " \
"or help(object) for help about object."
def __call__(self, *args, **kwds):
import pydoc
return pydoc.help(*arg s, **kwds)


Thanks, but how do I integrate this with cmd.Cmd?


Have you read the docs for the cmd module? E.g.,
http://www.python.org/doc/current/lib/Cmd-objects.html

"""
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>pytho n<versionstuff> \Lib\cmd.py
E.g.,
D:\Python23\Lib \cmd.py
or
D:\Python-2.4b1\Lib\cmd.p y
for me.
Look in cmd.py at class Cmd method do_help:

def do_help(self, arg):
if arg:
# XXX check arg syntax
try:
func = getattr(self, 'help_' + arg)
except AttributeError:
try:
doc=getattr(sel f, 'do_' + arg).__doc__
if doc:
self.stdout.wri te("%s\n"%str(d oc))
return
except AttributeError:
pass
[1] --> self.stdout.wri te("%s\n"%str(s elf.nohelp % (arg,)))
return
func()
else:
# ... generates topic listing

Probably you can write your own Cmd subclass and override do_help
and modify at [1] to do the pydoc call as in Peter's snippet.
Hopefully no weird interactions, but it should be easy to try ;-)

HTH

Regards,
Bengt Richter
Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2903
by: Donnie Leen | last post by:
I wrote a program embbed boost.python, each thread running a sub-interpreter, i made a module implement by boost.python, and i wish this module imported in each sub-interpreter, i find that the module could initialize only once, otherwise the boost.python will throw a exception said that something already registered; second conversion method...
6
1666
by: DE | last post by:
Hello, Some long time ago, I used to use Tcl/Tk. I had an tcl embedded into my app. The coolest thing was however, I was able to attach to the interpreter (built in to my app) via a tcl shell in which I could type in regular tcl code which would be interpreted by the interpreter of my application. Naturally, it was possible to call tcl...
12
12269
by: Rex Eastbourne | last post by:
Hi, I'm interested in running a Python interpreter in Emacs. I have Python extensions for Emacs, and my python menu lists "C-c !" as the command to run the interpreter. Yet when I run it I get the message "Spawning Child Process: invalid argument." What do I need to do/download to fix this? I read in a post in this group from a while...
12
1854
by: ozbear | last post by:
If one were writing a C interpreter, is there anything in the standard standard that requires the sizeof operator to yield the same value for two different variables of the same type? Let's assume that the interpreter does conform to the range values for, say, type int, but allocates storage for the variables based on their value. So, for...
5
4614
by: Russ | last post by:
I wrote a simple little function for exiting with an error message: def error ( message ): print_stack(); exit ("\nERROR: " + message + "\n") It works fine for executing as a script, but when I run it interactively in the python interpreter it kills the interpreter. That's not what I want. Is there a simple way to have a script terminate...
0
1094
by: Ole Nielsby | last post by:
I just wonder if this is possible with C++/clr. I'm trying to .NET-enable an interpreter for a Lisp flavoured language, the interpreter written in NASM which I have managed to port to MASM. However the VS2005 debugger is giving me a really hard time - seems it doesn't cope well with mixing MASM with C++/clr, so I am considering a rewrite...
3
1563
by: Robin Becker | last post by:
As part of some django usage I need to get some ReportLab C extensions into a state where they can be safely used with mod_python. Unfortunately we have C code that seems incompatible with mod_python and I'm looking for ways to improve the situation. Basically the main things that are wrong are all privately cached copies of python...
3
1433
by: Nils Overas Bergen | last post by:
I have created a Python application in Windows XP which uses WxWidgets. When I start the application from the Python interpreter I get one empty interpreter window in addition to the application window. Is there a way to close the interpreter window without closing the application? Or, can I start the interpreter and the application script...
16
9206
by: lawrence k | last post by:
I've never before written a PHP script to run on my home Ubuntu machine (though I've written dozens of PHP cron jobs for my web server), so I thought I'd start off with a very simple test: #!/usr/share/php5 <?php echo "hello"; ?>
1
1828
by: John Boy | last post by:
First post and very much a newbie to Python. Have 2.5 on Linux (GG). I think I have set up PYTHONPATH correctly in that I can import a module apply_bp and it complains about line 20 in apply_bp which is: import sys, aipy, numpy, os At the interpreter prompt, however, I can import sys, numpy etc. and can do dir() and see the entry points...
0
7894
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8176
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8321
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7931
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5699
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3841
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2331
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1426
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.