1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| class cParent:
def __init__(self):
self.tabEnfant1 = []
self.tabEnfant2 = []
def create1(self, val):
self.tabEnfant1.append(self.cEnfant(val))
def create2(self, val):
self.tabEnfant2.append(cParent.cEnfant(val))
class cEnfant:
def __init__(self, val):
self.val = val
print "Constructeur normal, val = %s" % val
class cEnfant2:
def __init__(self, val):
self.val = val
print "Constructeur modifié, val = %s" % val
p=cParent()
p.create1(12)
p.create2(25)
p.cEnfant = cEnfant2
p.create1(13)
p.create2(26)
for fils in p.tabEnfant1:
print fils.val
for fils in p.tabEnfant2:
print fils.val |
Partager