Order Of Inheritance In Python Classes
I have a class ExampleSim which inherits from base class Physics: class Physics(object): arg1 = 'arg1' def physics_method: print 'physics_method' class ExampleSim(
Solution 1:
Yes, you can do multiple inheritance.
classPhysics(object):
defphysics_method(self):
print'physics'classExampleSim(Physics):
defphysics_method(self):
print'example sim'classPhysicsMod(Physics):
defphysics_method(self):
print'physics mod'classExampleSimMod(PhysicsMod, ExampleSim):
pass
e = ExampleSimMod()
e.physics_method()
// output will be:
// physics mod
please note the order of class in ExampleSimMod
matters. The's a great article about this.
I modified your code a bit for demonstration reason. Hope my answer can help you!
Post a Comment for "Order Of Inheritance In Python Classes"