O'Reilly logo
  • Shobana Shanker thinks this is interesting:

The edge_distance_from_origin’s code is slightly different from before because it now accesses the base class’s distance_from_origin property instead of calling a distance_from_origin() method


Cover of Programming in Python 3: A Complete Introduction to the Python Language, Second Edition


this is a bit misleading. You got to implement distance_from_origin as a property in the base class. If you leave the base class implementation as a method, you still need to call base class as method. In addition, if you haven't reimplemented a method or reassigned a variable in the derived class, you can call that method or variable either by super(). or self. This is Python's polymorphism at work. Syntactically, it will work either way However, for those methods that you are trying to reimplement by reusing some of the functionality of the super class i.e. you need to delegate some work to the super class to reuse its implementation, you got to call super().method_name in that case. u can't use self bcoz of recursion ...