Last active
September 20, 2016 06:32
-
-
Save mbylstra/aae6eac98d162a5cc9c2 to your computer and use it in GitHub Desktop.
python mixin inheritance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
# | |
# MixinParent | |
# | | |
# Mixin A | |
# └--┐ | | |
# B | |
class A(object): | |
def test(self): | |
# super(A, self).test() #if put in, AttributeError: 'super' object has no attribute 'test' | |
print 'A' | |
class MixinParent(object): | |
def test(self): | |
super(MixinParent, self).test() #if left out, A's test() method will not be called. | |
print 'MixinParent' | |
class Mixin(MixinParent): | |
def test(self): | |
super(Mixin, self).test() | |
print 'Mixin' | |
class B(Mixin, A): | |
def test(self): | |
super(B, self).test() | |
print 'B' | |
b = B() | |
b.test() | |
# output: | |
# > A | |
# > MixinParent | |
# > Mixin | |
# > B |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment