Didn’t call super() __init__ in your Python class? Attributes normally set on the parent won’t be on the child!
The most common place we use super() in Python? __init__:
Misspelled the method you invoke via super() in a Python method? It’s a runtime error: We get: AttributeError: ‘super’ object has no attribute ‘y’
A Python method can invoke a method in the parent class with super(): super() doesn’t invoke the method. It’s a proxy on which you invoke the method you want.
If a Python subclass defines a method with the same name as the parent, the parent’s method isn’t invoked:
Thanks to ICPO/MRO, if a child Python class doesn’t define a method, the parent method will be invoked:
I just got back from PyCon US. It was delightful; I saw old friends, met new ones, gave a tutorial on decorators, and spoke at the education summit. I’m a PyCon US sponsor, which means that I also had a booth, giving out T-shirts, books, stickers, and flyers about the LernerPython platform. Of course, the…
Inheritance in Python changes the attribute lookup path, aka the “method resolution order,” or MRO: Child.__mro__ # (__main__.Child, object) Child.__mro__ # (__main__.Child, __main__.Parent, object)
Set one Python class to inherit from another by putting the parent in (): Child.__bases__ # who does Child inherit from?
Python uses attributes where other languages use different terms (and data structures): – Instance variable — attribute on an instance (self)– Class variable — attribute on a class– Method — callable (function) attribute on a class