自我的捷径.__ class__

时间:2019-10-08 08:55:46

标签: python-3.x

有时我发现自己正在访问班级成员。在一个项目中,我什至在类定义中包含类定义。

在这种情况下,我经常发现mysql键入self.__class__.<member_name>self.__class__.<contained_class_name>。在几乎所有用例中,self.__class__比实际的类名更多的字符,因此使用self.__class__很烦人。但是,

  • 我不想在类定义中对类名进行硬编码,
  • self.__class__.some_attribute与(始终)与使用类名不同,例如MyClass.some_attribute,我想要前者的行为

所以我在想。有self.__class__的缩写吗?

0 个答案:

没有答案