下面是我想记录的一个类的草图。我的第一个愿望是从Jupyter内部获得简短的帮助。
这些帮助调用按我的预期工作:
帮助(热):显示所有内容(类、方法和属性)
帮助(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 '''
属性的要点是thermo.take
获取getter返回的对象(在本例中为Take
对象)。这就是为什么help(thermo.take)
等同于help(Take())
(或者无论你的"获取对象"是什么)。
可以通过在类的属性上调用 help
来绕过此行为:
help(substances.take)
# Or
help(type(thermo).take)
这是有效的,因为没有你调用take
的self
,所以它唯一需要返回的是你定义的属性。