views:

66

answers:

3

Following sample is taken from "Dive into python" book.

class MP3FileInfo(FileInfo):
    "store ID3v1.0 MP3 tags"
    tagDataMap = ...

This sample shows documenting the MP3FileInfo, but how can I add help to MP3FileInfo. tagDataMap

+1  A: 

Change it into a property method.

Wahnfrieden
I wonder about this, since then you have to create explicit getter, setter and deleter (I want all three), only to have it behave normally. Is there a way to set default methods for these that simply wrap a class attribute?
kaizer.se
Just mention tagDataMap inside your class docstring.
Wahnfrieden
...By using a multi-line docstring: '''foo bar'''
Wahnfrieden
+3  A: 

The PEP 224 on attribute docstrings was rejected (long time ago), so this is a problem for me as well, sometimes I don't know to choose a class attribute or an instance property -- the second can have a docstring.

kaizer.se
A: 

Do it like this:

class MP3FileInfo(FileInfo):
    """Store ID3v1.0 MP3 tags."""

    @property 
    def tagDataMap(self):
        """This function computes map of tags.

        The amount of work necessary to compute is quite large, therefore
        we memoize the result.

        """
        ...

Note though you really shouldn't make a separate docstring if the attribute has only a one-line description. Instead, use

class MP3FileInfo(FileInfo):
    """Store ID3v1.0 MP3 tags.

    Here are the attributes:
        tagDataMap -- contains a map of tags

    """

    tagDataMap = ...
ilya n.
in my case attribute has public visibility - that is why help(tagDataMap) is what I want to get
Dewfy