For new-style classes, use type(self) to get the "current" class:
def create_another(self): return type(self)()
You can also use self.__class__ , as this value will use the type() value, but it is recommended that you always use the API method.
For old-style classes (python 2, not inheriting from object ), type() not so useful, so you are forced to use self.__class__ :
def create_another(self): return self.__class__()
Martijn pieters
source share