简体   繁体   中英

How to print docstring for class attribute/element?

I have a class:

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

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

I can print the class docstring by typing:

print(Holiday.__doc__)

This outputs as:

Holiday is an activity that involves taking time off work 

How can I print the docstring for Hotel which is a Class attribute/element?

What I've tried

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.

I've also tried the help() function to no avail.

NB

Sphinx seems to be able to extract the docstrings of class attributes and include them in readthedocs so I'm hoping there's a way

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

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

Unfortunately, there is currently no such implementation of attribute docstrings in Python. There was a PEP that suggested implementing this functionality, but it was rejected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM