I recently learned that the ``namedtuple`` class provides a definition of ``__str__`` which does the thing we usually want for debugging. For example, the class ``namedtuple('X', ['a', 'b', 'c'])`` has the method:
def __str__(self):
return "X(a = %s, b = %s, c = %s)" % (self.a, self.b, self.c)
Whenever we say ``class Y(namedtuple('X', ...))``, the class ``Y`` inherits ``X.__str__``; thus, so long as ``X`` and ``Y`` are textually the same name, the inherited method will do the right thing. In our code we always make sure the names match; thus, we could get rid of all our explicit ``Y.__str__`` method definitions.
Comment 1 by kateso...@chromium.org
, Sep 15 2017