Docstrings and class Attributes
steve+comp.lang.python at pearwood.info
Mon Aug 8 20:32:18 CEST 2011
> Is it possible to put a doc string on a class attribute? Something
> like this
> class Test (object):
> fred = 10
The short answer is, no.
The longer answer is, maybe, if you can make Test.fred be some sort of
object with a docstring:
fred = MyInt(10)
But the hard part is ensuring that Test.fred doesn't get replaced:
>>> Test.fred = 11
'int(x[, base]) -> integer\n\nConvert a string or number ...'
Not impossible to solve, but an awful lot of trouble for very little
benefit. Just put your documentation in the class, where people expect to
Test.fred is an attribute.
fred = 10
More information about the Python-list