Adding docstrings to namedtuples?

前端 未结 10 1540
死守一世寂寞
死守一世寂寞 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:22

    Came across this old question via Google while wondering the same thing.

    Just wanted to point out that you can tidy it up even more by calling namedtuple() right from the class declaration:

    from collections import namedtuple
    
    class Point(namedtuple('Point', 'x y')):
        """Here is the docstring."""
    

提交回复
热议问题