并行分配的自动属性(sphinxdoc)

2024-09-14 18:01:34 发布

您现在位置:Python中文网/ 问答频道 /正文

在记录实例变量时,我可以

class Foo:
    def __init__(self):
        self.spam = 4
        """Docstring for instance attribute spam."""

这不适用于平行作业

^{pr2}$

如何记录并行分配中的变量?在


Tags: 实例instanceselfforfooinitdef记录
2条回答

^{}用于单个属性。下面是一种与autoclassautomodule一起使用的方法:

class Foo:
    """
    :ivar spam: Description of spam
    :ivar bar: Description of bar
    :ivar moo: Description of moo
    """

    def __init__(self):
        self.spam, self.bar, self.moo = 4, 5, 6

与使用autoattribute得到的结果相比,输出看起来有点不同,但我非常喜欢它。在

我发现我可以在__init__doc string块中使用Sephix标记,使其看起来与使用autoattribute几乎相同。在

class Foo:
    def __init__(self):
        """
        Something something

        .. py:attribute:: spam

           Something about spam

        .. py:attribute:: bar

           Something about br

        .. py:attribute:: moo

           Something about moo
        """
        self.spam, self.bar, self.moo = 4, 5, 6

这看起来像 http://xrxr.github.io/RapidPygame/levelmgr.html (使用此技术完成解释和绘制清单。) 如果autoclass_content设置为'both' (如果你注意了,它们不是按字母顺序排列的)

这行得通,但我还是想知道有没有更好的办法。在

相关问题 更多 >