docstrings for data fields

mblume foobar at invalid.invalid
Thu May 3 12:12:30 EDT 2012


Am Thu, 03 May 2012 14:51:54 +0200 schrieb Ulrich Eckhardt:

> Hi!
> 
> My class Foo exports a constant, accessible as Foo.MAX_VALUE. Now, with
> functions I would simply add a docstring explaining the meaning of this,
> but how do I do that for a non-function member? Note also that ideally,
> this constant wouldn't show up inside instances of the class but only
> inside the class itself.
> 
> There are decorators for static functions or class functions, similarly
> there is one for instance properties but there isn't one for class
> properties. Would that be a useful addition?
> 
> Uli

Docstring for Foo?


>>> 
>>> class Foo:
...     """ exports a FOO_MAX value """
...     FOO_MAX = 42
... 
>>> 
>>> 
>>> 
>>> 
>>> help(Foo)
Help on class Foo in module __main__:

class Foo
 |  exports a FOO_MAX value
 |  
 |  Data and other attributes defined here:
 |  
 |  FOO_MAX = 42

>>> Foo.FOO_MAX
42
>>> 
>>> 
>>> 


HTH 
Martin



More information about the Python-list mailing list