I wonder if there is a way to get the class name automatically upon defining class attribute before initialization
class MyClass(object):
attribute1 = 1
attribute2 = 2 # This a simple example, MyClass has many other attributes
print className # normally one would use self.__class__.__name__ but self or cls are not defined at the level
def __init__(self):
a = 1
Purpose
In the framework I am working in, attribute1 and attribute2 are object instances (you will say everything is object oriented in python :) ) I want to set the class name to those attributes prior to MyClass initialization. MyClass get initialized a lot of times and it has much more than 2 attributes which makes the operation very time consuming to do at every initialization