str: a "nice" summary string describing this module
(self)
| 73 | >>> assert str(baz) == '<Baz(5)>' |
| 74 | """ |
| 75 | def __nice__(self): |
| 76 | """str: a "nice" summary string describing this module""" |
| 77 | if hasattr(self, '__len__'): |
| 78 | # It is a common pattern for objects to use __len__ in __nice__ |
| 79 | # As a convenience we define a default __nice__ for these objects |
| 80 | return str(len(self)) |
| 81 | else: |
| 82 | # In all other cases force the subclass to overload __nice__ |
| 83 | raise NotImplementedError( |
| 84 | f'Define the __nice__ method for {self.__class__!r}') |
| 85 | |
| 86 | def __repr__(self): |
| 87 | """str: the string of the module""" |