class 或 __init__ 构造函数中的文档字符串?
docstring in class or __init__ constructor?
似乎有两个地方可以放置 class:
的文档字符串
- 右下class定义:
class MyClass(object):
""" Summary of MyClass
Body
...
"""
- 在
__init__
构造函数的正下方:
...
def __init__(self, arg1, arg2):
""" Summary of MyClass
Body
...
"""
首选哪个?还是两者都可以?
它们可以同时存在,因为它们的用途不同。
The docstring for a class should summarize its behavior and list the public methods and instance variables. If the class is intended to be subclassed, and has an additional interface for subclasses, this interface should be listed separately (in the docstring). The class constructor should be documented in the docstring for its __init__
method. Individual methods should be documented by their own docstring.
强调我的。
此参考来自PEP 257 -- Docstring Conventions
似乎有两个地方可以放置 class:
的文档字符串- 右下class定义:
class MyClass(object):
""" Summary of MyClass
Body
...
"""
- 在
__init__
构造函数的正下方:
...
def __init__(self, arg1, arg2):
""" Summary of MyClass
Body
...
"""
首选哪个?还是两者都可以?
它们可以同时存在,因为它们的用途不同。
The docstring for a class should summarize its behavior and list the public methods and instance variables. If the class is intended to be subclassed, and has an additional interface for subclasses, this interface should be listed separately (in the docstring). The class constructor should be documented in the docstring for its
__init__
method. Individual methods should be documented by their own docstring.
强调我的。 此参考来自PEP 257 -- Docstring Conventions