Adding docstrings to namedtuples?

前端 未结 10 1531
死守一世寂寞
死守一世寂寞 2020-12-08 01:52

Is it possible to add a documentation string to a namedtuple in an easy manner?

I tried

from collections import namedtuple

Point = namedtuple(\"Poin         


        
10条回答
  •  一生所求
    2020-12-08 02:10

    Since Python 3.5, docstrings for namedtuple objects can be updated.

    From the whatsnew:

    Point = namedtuple('Point', ['x', 'y'])
    Point.__doc__ += ': Cartesian coodinate'
    Point.x.__doc__ = 'abscissa'
    Point.y.__doc__ = 'ordinate'
    

提交回复
热议问题