如何为类atrribute /元素打印文档字符串?

问题描述 投票:0回答:3

我有课:

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

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

我可以输入以下内容来打印类文档字符串:

print(Holiday.__doc__)

此输出为:

Holiday is an activity that involves taking time off work 

我如何打印作为Class属性/元素的Hotel的文档字符串?

我尝试过的

print(Holiday.Hotel.__doc__)

返回:

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

我也尝试过help()函数无济于事。

python django python-3.x django-models docstring
3个回答
1
投票

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

help_text

1
投票

[不幸的是,目前在Python中没有这样的属性文档字符串实现。有Hotel = models.CharField(max_length=255, help_text="Name of hotel") 建议实现此功能,但遭到拒绝。


-1
投票

可以与之互动显示

PEP

或者从代码中,您可以像在问题中那样使用help(Holiday.Hotel) 进行检索

__doc__
© www.soinside.com 2019 - 2024. All rights reserved.