in my project I have to repeat often such part of code:
class SimplePhysicObject(Object):
def __init__(self):
super(Object, self).__init__('SimplePhysicObject')
But instead of SimplePhysicObject there is new string each time. Are there any ways to write some macro to make this work easier? Something like:
DoTemplate(NewObject)
==>
class NewObject(Object):
def __init__(self):
super(Object, self).__init__('NewObject')
UPD Sorry, Object is my own class declared before in code
I don’t see a reason why
Objectshould need the actual class name as a parameter. You can access the actual class name inObjectviaself.__class__.__name__:will print
This is slightly different than your original code: If you derive from
SimplePhysicObject, thenameattribute will be set to the name of the derived class, whereas your original code would continue to use"SimplePhysicObject".