[Tutor] redirecting help -- is this a bad idea?
kent_johnson at skillsoft.com
Sun Aug 1 01:03:57 CEST 2004
You are right on both counts.
Assigning pyhelp = help makes both variables point to the same object (the
original instance of _Helper). If you then rebind help to a different
object, the binding to pyhelp persists.
The way to think about assignment in Python is that the variable is just a
reference to the actual value. Python variables are just names for values.
Values have their own existence. An assignment statement binds a variable
to a value. "pyhelp = help" means, "Whatever value help is bound to, bind
pyhelp to the same thing."
(I hope I haven't confused you too much, I don't think I'm explaining this
I missed the point that your _PyHelper class has a different __repr__()
than the standard one. You do need a new class if you want to change the
behavior of the built-in help.
At 06:15 PM 7/31/2004 -0400, Brian van den Broek wrote:
>>- 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.
>OK, let me run that back to see if I follow the intent: Before I make my
>own help, the standard one is present as always. Then
>pyhelp = help
>assigns pyhelp to that standard help function, and that assignment
>persists even after I have done my thing to make help call my custom function?
>If I've got that right, then won't there be the small problem that typing
>pyhelp at the prompt will give the old instructions of help? (As in, it
>will still say "help(object) for help about object", etc.) But that won't
>work as expected, once I've redirected help. I'd thought I needed to use
>the class PyHelper just so that pyhelp would print out the new, customized
>way to get to the pydoc functionality.
More information about the Tutor