Docstrings for class attributes

Diez B. Roggisch deets at nospam.web.de
Tue Sep 23 14:20:15 CEST 2008


Tom Harris wrote:

> Greetings,
> 
> I want to have a class as a container for a bunch of symbolic names
> for integers, eg:
> 
> class Constants:
>     FOO = 1
>     BAR = 2
> 
> Except that I would like to attach a docstring text to the constants,
> so that help(Constants.FOO) will print some arbitrary string. Sort of
> a very limited implementation of PEP 224. The only solution that I can
> see is to subclass int.__new__(), since once I have an int all it's
> attributes are immutable.

Epydoc interprets strings like this as doc-strings:

"""
FOO is not a bar
"""
FOO = "foo"


However, it won't get recognized by help of course.

Diez



More information about the Python-list mailing list