On 06/29/2010 02:37 AM, Ben Finney wrote: > Brian Blais <bbl...@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" >
No, you can't. Well, yeah, you can. But you can't. But you can. Ahrgh I want Python 2.x to go away. It's so inconsistent and silly. % python2.6 Python 2.6.5+ (release26-maint, Jun 28 2010, 19:46:36) [GCC 4.4.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> class OLD: pass ... >>> class NEW(object): pass ... >>> OLD.__doc__ = "foo" >>> NEW.__doc__ = "bar" Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: attribute '__doc__' of 'type' objects is not writable >>> -- http://mail.python.org/mailman/listinfo/python-list