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!"""
As mentioned above, Python docstrings are strings used right after the definition of a function, method, class, or module (like in Example 1). They are used to document our code. We can access these docstrings using the __doc__ attribute.
The docstring for a module function should include the same items as a class method: A brief description of what the function is and what it's used for. Any arguments (both required and optional) that are passed including keyword arguments.
Python documentation string or commonly known as docstring, is a string literal, and it is used in the class, module, function, or method definition.
Python documentation strings (or docstrings) provide a convenient way of associating documentation with Python modules, functions, classes, and methods. It's specified in source code that is used, like a comment, to document a specific segment of code.
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"
It is possible to make documentation of module's data, with use of epydoc syntax. Epydoc is one of the most frequently used documentation tools for Python.
The syntax for documenting is #:
above the variable initialization line, like this:
# module.py: #: Very important data. #: Use with caution. #: @type: C{str} data = "important data"
Now when you generate your documentation, data
will be described as module variable with given description and type str
. You can omit the @type
line.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With