Docstrings and class Attributes

Ethan Furman ethan at stoneleaf.us
Mon Aug 8 14:58:21 EDT 2011


Steven D'Aprano wrote:
> Eric Snow wrote:
> 
>> On Mon, Aug 8, 2011 at 6:37 AM, Nick <nickle at gmail.com> wrote:
>>> Is it possible to put a doc string on a class attribute? Something
>>> like this
>> You can put a docstring on a property (which is a function):
>>
>> class Test(object):
>>     @property
>>     def fred(self):
>>         "attribute"
>>         return 10
> 
> Which, however, doesn't really help:
> 
>--> t = Test()
>--> t.fred.__doc__
> 'int(x[, base]) -> integer\n\nConvert a string or number to an integer ...'
> 
> 
> The problem is that t.fred returns an integer, so t.fred.__doc__ returns the
> docstring from the integer, not for the property.
> 
>--> t.__class__.fred.__doc__
> 'attribute'

So if property docstrings are so hard to get to, what's the point in 
having them?

~Ethan~



More information about the Python-list mailing list