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.
class Physics(object):
def physics_method(self):
print 'physics'
class ExampleSim(Physics):
def physics_method(self):
print 'example sim'
class PhysicsMod(Physics):
def physics_method(self):
print 'physics mod'
class ExampleSimMod(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"