How to comment constant values?

Diez B. Roggisch deets at nospam.web.de
Sun Jul 26 18:47:08 EDT 2009


Chris Rebert schrieb:
> On Sun, Jul 26, 2009 at 2:49 PM, Erwin Mueller<devent at deventm.org> wrote:
>> Hello, I'm new to Python (using it for two months) and I wonder how can I
>> comment the const. values with the doc-strings. I.e. if I have code:
>>
>>> FRACTION_MIN = 1
>>> FRACTION_MAX = 10
>>>
>>> class Fraction(collections.MutableSequence):
>>>    '''Model a fraction with denominators.
>>>
>>>    It contains one ore more denomintors in a list for quick access.
>>>    The class is thread save, it uses a lock for all operations.
>>>    '''
>>>
>>>    def __init__(self):
>>>               # ...
>> The class and the methods can have doc-strings, but what about the const.
>> values, FRACTION_MIN and FRACTION_MAX?
> 
> Only modules, classes, and functions/methods can have docstrings
> associated with them.
> For anything else, you have to use comments; or you can mention them
> in the docstrings of related things.

While this is technically true, writing docstrings to constants (module 
or classlevel) works when one uses tools such as epydoc to generate 
documentation.

Diez



More information about the Python-list mailing list