dynamically modify help text

Steven D'Aprano steve-REMOVE-THIS at cybersource.com.au
Mon Jun 28 22:19:34 EDT 2010


On Tue, 29 Jun 2010 10:37:44 +1000, Ben Finney wrote:

> Brian Blais <bblais at bryant.edu> writes:
> 
>> On Jun 28, 2010, at 14:25 , Chris Rebert wrote:
>> > __doc__ is normally defined on classes, e.g. `A`, not instances, e.g.
>> > `a`. help() looks for __doc__ accordingly.
>>
>> so that gets back to my original question: can I change this text at
>> runtime.  Doesn't look like I can, because it is defined for classes
>> rather than instances.  Am I thinking about this correctly?
> 
> Classes are objects. You can change the ‘__doc__’ attribute of a class
> object the same as you'd change it for any other object::
> 
>     A.__doc__ = "new docstring"


True, but what you can't do is:



a = A()
a.__doc__ = "new docstring"



unless you jump through hoops with __getattribute__ or descriptors.



-- 
Steven






More information about the Python-list mailing list