如何打印 class attribute/element 的文档字符串?

How to print docstring for class attribute/element?

我有一个class:

class Holiday(ActivitiesBaseClass):
    """Holiday is an activity that involves taking time off work"""

    Hotel = models.CharField(max_length=255)
    """ Name of hotel """

我可以通过键入以下内容来打印 class 文档字符串:

print(Holiday.__doc__)

这输出为:

Holiday is an activity that involves taking time off work 

如何打印酒店的文档字符串 Class attribute/element?

我试过的

print(Holiday.Hotel.__doc__)

returns:

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

我也试过 help() 功能没用。

N.B

Sphinx 似乎能够提取 class 属性的文档字符串并将它们包含在 readthedocs 中,所以我希望有办法

不认为可以为特定字段添加文档字符串,但您可以使用字段的 help_text 参数代替:

Hotel = models.CharField(max_length=255, help_text="Name of hotel")

不幸的是,目前 Python 中没有这样的属性文档字符串实现。曾有 PEP 建议实现此功能,但被拒绝了。