docstring(myClass.aProperty)不返回aProperty的docstring

2024-04-16 12:45:06 发布

您现在位置:Python中文网/ 问答频道 /正文

下面是我想记录的一个类的草图。 我的第一个愿望是从Jupyter内部获得短期帮助

这些帮助电话按我的预期工作:

帮助(thermo):显示所有内容(类、方法和属性)

帮助(thermo.select):显示选择帮助

帮助(thermo.table):显示表格帮助

不幸的是,这一个并不像我预期的那样有效:

help(thermo.take)不会从take属性返回帮助

相反,该语句返回take对象的所有属性(2000+)

你能澄清一下发生了什么吗, 并建议我如何获得帮助(thermo.take)按我的意愿工作

谢谢

class substances(list, metaclass=substancesMeta):
    ''' A thermodynamic database of substances '''
    @property
    def take(self):
        ''' A simple way to take a substance. '''

    def select(self, ... ):
        ''' Select a subset of the database. '''

    def table(self, **kwargs):
        ''' Create a pandas dataframe from substances object '''

Tags: ofself内容thermo属性def记录table
1条回答
网友
1楼 · 发布于 2024-04-16 12:45:06

属性的要点是thermo.take获取getter返回的对象(在本例中是Take对象)。这就是为什么help(thermo.take)等同于help(Take())(或者你的“take对象”是什么)

您可以通过对类的属性调用help来绕过此行为:

help(substances.take)
# Or
help(type(thermo).take)

这是因为没有self可供调用take,因此它必须返回的唯一内容是您定义的属性

相关问题 更多 >