new-style class initialization

robin and jim robinjim at earthlink.net
Sun Mar 17 12:22:46 EST 2002


What is the correct way to write the following where the number of arguments
to the initializer changes throughout the inheritance hierarchy?

class A(object):
   def __init__(self, x): print "A's initializer called"
   def m(self): print "save A's data"
class B(A):
   def __init__(self): print "B's initializer called"; super(B,
self).__init__('B')
   def m(self): print "save B's data"; super(B, self).m()
class C(A):
   def __init__(self): print "C's initializer called"; super(C,
self).__init__('C')
   def m(self): print "save C's data"; super(C, self).m()
class D(B, C):
   def __init__(self): print "D's initializer called"; super(D,
self).__init__()
   def m(self): print "save D's data"; super(D, self).m()
d = D()
d.m()

I have tried some permutations of defining __new__(), but obviously do not
know what I'm doing.





More information about the Python-list mailing list