Docstrings and class Attributes
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Mon Aug 8 14:26:09 EDT 2011
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'
--
Steven
More information about the Python-list
mailing list