Search code examples
pythondocstring

Docstrings for data?


Is there a way to describe the module's data in a similar way that a docstring describes a module or a funcion?

class MyClass(object):
    def my_function():
        """This docstring works!"""
        return True
    my_list = []
    """This docstring does not work!"""

Solution

  • To my knowledge, it is not possible to assign docstrings to module data members.

    PEP 224 suggests this feature, but the PEP was rejected.

    I suggest you document the data members of a module in the module's docstring:

    # module.py:
    """About the module.
    
    module.data: contains the word "spam"
    
    """
    
    data = "spam"