In general, inheritance is the right way, as other posters have noted.
However, if you really want to recreate the same type with a different name and without inheritance, you can do this as follows:
class B(object): x = 3 CopyOfB = type('CopyOfB', B.__bases__, dict(B.__dict__)) b = B() cob = CopyOfB() print bx
You must be careful with variable attribute values:
class C(object): x = [] CopyOfC = type('CopyOfC', C.__bases__, dict(C.__dict__)) c = C() coc = CopyOfC() cxappend(1) coc.x.append(2) print cx
Florian Brucker Nov 14 2018-12-12T00: 00Z
source share