Is it possible to indirectly access current class name in python?
This question already has an answer here:
You can make use of self keyword in python instead of using the current class name.
class MyLongAdvancedClassName:
...
_template = " My long advanced text %i "
def method(self):
print self._template
Hope it helps.
Probably what you are looking for is to use self (look at San's answer). However this requires you to have an instance of the class. If you want to do it with the class itself then you can use the classmethod decorator like this:
class MyLongAdvancedClassName:
...
_template = " My long advanced text %i "
@classmethod
def method(cls):
print cls._template
链接地址: http://www.djcxy.com/p/40952.html
上一篇: 从实例获取模型名称