擅长:python、mysql、java
<p>在Python 3中,不需要包装器,因为类型的<code>__doc__</code>属性是可写的。</p>
<pre><code>from collections import namedtuple
Point = namedtuple('Point', 'x y')
Point.__doc__ = '''\
A 2-dimensional coordinate
x - the abscissa
y - the ordinate'''
</code></pre>
<p>这与标准类定义非常对应,其中docstring紧跟在头后面。</p>
<pre><code>class Point():
'''A 2-dimensional coordinate
x - the abscissa
y - the ordinate'''
<class code>
</code></pre>
<p>这在Python 2中不起作用。</p>
<p><code>AttributeError: attribute '__doc__' of 'type' objects is not writable</code>。</p>