[Edu-sig] multiple inheritance and method resolution order
kirby urner
kirby.urner at gmail.com
Fri Sep 7 16:23:57 EDT 2018
Addendum (copyleft, re-use and modify at will)
+ related links
[The]
> "where's Waldo" exercise and this investigation into the MRO may be
> combined: bury a waldo() instance or class method somewhere in the Genesis
> family
> [tree],
>
===
class Gen0 (object):
"""the Old One"""
def __init__(self):
print("__init__ of {}".format("Gen0"))
class Adam(Gen0):
"""one of two in Gen1"""
def __init__(self):
super().__init__()
print("__init__ of {}".format("Adam"))
class Eve(Gen0):
"""one of two in Gen1"""
def __init__(self):
super().__init__()
print("__init__ of {}".format("Eve"))
def waldo(self):
print("Waldo in {}".format("Eve"))
class Cain(Adam, Eve):
"""Gen2"""
def __init__(self):
super().__init__()
print("__init__ of {}".format("Cain"))
class Abel(Adam, Eve):
"""Gen2"""
def __init__(self):
super().__init__()
print("__init__ of {}".format("Abel"))
class Seth(Adam, Eve):
"""Gen2"""
def __init__(self):
super().__init__()
print("__init__ of {}".format("Seth"))
class Azura(Adam, Eve):
"""Gen2"""
def __init__(self):
super().__init__()
print("__init__ of {}".format("Azura"))
class Enosh(Seth, Azura):
"""Gen3"""
def __init__(self):
super().__init__()
print("__init__ of {}".format("Enosh"))
class Kenan(Enosh):
"""Gen4"""
def __init__(self):
super().__init__()
print("__init__ of {}".format("Kenan"))
class Mahalaleel(Kenan):
"""Gen5"""
def __init__(self):
super().__init__()
print("__init__ of {}".format("Mahalaleel"))
class Jared(Mahalaleel):
"""Gen6"""
def __init__(self):
super().__init__()
print("__init__ of {}".format("Jared"))
class Enoch(Jared):
"""Gen7"""
def __init__(self):
super().__init__()
print("__init__ of {}".format("Enoch"))
class Methusela(Enoch):
"""Gen8"""
def __init__(self):
super().__init__()
print("__init__ of {}".format("Methusela"))
def waldo(self):
print("Waldo in {}".format("Methusela"))
class Elisha(Enoch):
"""Gen8"""
def __init__(self):
super().__init__()
print("__init__ of {}".format("Elisha"))
class Lamech(Methusela):
"""Gen9"""
def __init__(self):
super().__init__()
print("__init__ of {}".format("Lamech"))
class Ashmua(Elisha):
"""Gen9"""
def __init__(self):
super().__init__()
print("__init__ of {}".format("Ashmua"))
def waldo(self):
print("Waldo in {}".format("Ashuma"))
class Noah(Lamech, Ashmua):
"""Gen10"""
def __init__(self):
super().__init__()
print("__init__ of {}".format("Noah"))
if __name__ == "__main__":
import inspect
subject = Noah()
subject.waldo()
print(inspect.getmro(subject.__class__))
===
Related posts:
https://grokbase.com/t/python/edu-sig/066kd86zh1/rich-data-structures-plus-knowledge-domain-object-sets
https://mail.python.org/pipermail/edu-sig/2012-December/010709.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/edu-sig/attachments/20180907/843f642f/attachment-0001.html>
More information about the Edu-sig
mailing list