下面是我想要记录的一个类的草图。我的第一个愿望是从木星内部得到短暂的帮助。
这些帮助调用如我所料的工作:
帮助(热):显示一切(类、方法和属性)
帮助(thermo.select):显示选择的帮助
帮助(thermo.table):显示表帮助
不幸的是,没有像我预期的那样工作:
“帮助”(thermo.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 '''发布于 2017-10-24 16:11:23
属性的要点是,thermo.take将获取getter返回的对象(在本例中,是Take对象)。这就是为什么help(thermo.take)等同于help(Take()) (或者您的“采取对象”是什么)的原因。
您可以通过对类的属性调用help来绕过此行为:
help(substances.take)
# Or
help(type(thermo).take)这是因为您没有调用self的take,所以它必须返回的唯一东西是您定义的属性。
https://stackoverflow.com/questions/46915016
复制相似问题