[Tutor] redirecting help -- is this a bad idea?

Brian van den Broek bvande at po-box.mcgill.ca
Sat Jul 31 02:22:36 CEST 2004


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




More information about the Tutor mailing list