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

Kent Johnson kent_johnson at skillsoft.com
Sat Jul 31 15:13:41 CEST 2004


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



More information about the Tutor mailing list