[Tutor] redirecting help -- is this a bad idea? (original) (raw)
Kent Johnson kent_johnson at skillsoft.com
Sat Jul 31 15:13:41 CEST 2004
- Previous message: [Tutor] redirecting help -- is this a bad idea?
- Next message: [Tutor] Understanding DBAPI cursor.execute
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Brian,
A couple of thoughts:
You might consider just making your classes work well with pydoc. The built-in help is introspecting the docstrings for the module you ask for help on. If you write docstrings for your module, built-in help will document it. Take a look at some library modules and the corresponding help to see how this works. If you go this way, your help will be integrated with the help for built-in objects, so your user won't have to figure out which help to use.
If you continue down the path you show below, there is no need to define _PyHelper. You can just assign pyhelp = help
Then define your own helper and assign it to help.
BTW you are not redefining builtin.help when you do this, you are shadowing it with a definition of help in the current global namespace.
Kent
At 08:22 PM 7/30/2004 -0400, Brian van den Broek wrote:
Hi all,
I'm making my first use of classes and also over-riding python builtins. I'd like to run what I am doing by the list as a sanity check and see if I get a giant don't do that! back :-) What I am trying to do is create a set of programs for use by a friend who is even less computer literate than I. =-O Part of my aim is to make it self-documenting in an easy to use way. So, I want to redirect the help command to my own help function for my set of programs, while still preserving the normal help behaviour under another name. Having dipped into site.py to see how help was able to work both by typing "help" and by typing "help()", I saw it was implemented with a class: class Helper: 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(*args, **kwds) builtin.help = Helper()
I used this as the basis of my redirection of "help". The function that does the work of my help system is tell(). So I've done the following: class Helper: def repr(self): _return "Type help() for interactive help, " _ _"or help(object) for help about object.\n" _ "(For Python's own help function, type pyhelp.)" def call(self, *args, **kwds): return tell(*args, **kwds) help = Helper() class PyHelper: def repr(self): _return "Type pyhelp() for interactive help, " _ "or pyhelp(object) for help about object." def call(self, *args, **kwds): import pydoc return pydoc.help(*args, **kwds) pyhelp = PyHelper() Profoundly wrong or just fine? Best, Brian vdB
Tutor maillist - Tutor at python.org http://mail.python.org/mailman/listinfo/tutor
- Previous message: [Tutor] redirecting help -- is this a bad idea?
- Next message: [Tutor] Understanding DBAPI cursor.execute
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]