""" Ex. 9.1 from "A primer on..." Demonstrate the "magic" of inheritance by creating a dummy subclass that adds nothing to the base class, and inspect its contents using the dir-function. """ import numpy as np class Line: def __init__(self, c0, c1): self.c0 = c0 self.c1 = c1 def __call__(self, x): return self.c0 + self.c1*x def table(self, L, R, n): """Return a table with n points for L <= x <= R.""" s = '' for x in np.linspace(L, R, n): y = self(x) s += f'{x:12g} {y:12g}\n' return s #dummy class, inherits everything from Line, but adds nothing: class Parabola0(Line): pass #create an instance and check its attributes: p1 = Parabola0(1, 1) print(dir(p1)) print(p1.__dict__) """ Terminal> python dir_subclass.py ['__call__', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'c0', 'c1', 'table'] {'c0': 1, 'c1': 1} """