In Python 3, no wrapper is needed, as the __doc__
attributes of types is writable.
from collections import namedtuple
Point = namedtuple('Point', 'x y')
Point.__doc__ = '''
A 2-dimensional coordinate
x - the abscissa
y - the ordinate'''
This closely corresponds to a standard class definition, where the docstring follows the header.
class Point():
'''A 2-dimensional coordinate
x - the abscissa
y - the ordinate'''
<class code>
This does not work in Python 2.
AttributeError: attribute '__doc__' of 'type' objects is not writable
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…