如果你不声明类显式的属性 - 我以为你只是为它们分配在构造函数中值 - 你可以把自己的意见与类注释起来:
"""
Class: MyClass
Describe the class here.
Attributes:
attr1 - First attribute of the class
attr2 - Second one
"""
class MyClass:
def __init__(self, arg1):
self.attr1 = arg1
self.attr2 = "attr2"
您可以为方法做同样的太。这是最简单的方法,但是您不会在索引中分别列出类别成员,这是一个巨大的缺点。如果你提供了一个前缀的文件中每类成员的引用将工作:
"""
Class: MyClass
Describe the class here.
Attribute: attr1
First attribute of the class
Attribute: attr2
Second one
"""
class MyClass:
# Constructor: __init__
# Describe the constructor.
#
# Parameters:
# arg1 - The first argument.
def __init__(self, arg1):
self.attr1 = arg1
self.attr2 = "attr2"
# Method: method1
# Describe the method here.
def method1(self):
print("method1")
加前缀的评论是不是在评论刚刚实施前通常放反正方法有问题。如果你没有明确地声明你的属性来为自己的评论留下自然的位置,它会使课堂评论杂乱无章。您也可以将评论分成更多部分。注意你可以混合行和块注释。
两个备注:如果您想使用"""
分隔块注释,而不是仅仅通过#
前缀行注释,你必须将下列行添加到Languages.txt
在NaturalDocs项目目录:显然
Alter Language: Python
Block Comment: """ """
你例如关键字Attribute
而不是Property
,默认情况下它由NaturalDocs识别。以下内容添加到Topics.txt
在NaturalDocs项目目录有它承认过:
Alter Topic Type: Property
Add Keywords:
attribute, attributes
--- Ferda
似乎并没有得以顺利。我通常只在__init__函数内声明类属性。 – HWende 2012-04-04 11:36:28
我使用的是NaturalDocs,python有基本支持:**仅限显式文档。只有您编写Natural Docs文档的内容才会显示在输出中。** – HWende 2012-04-04 11:38:19