[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


Brian,

A couple of thoughts:

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



More information about the Tutor mailing list