str: a "nice" summary string describing this module
(self)
| 354 | >>> assert str(baz) == '<Baz(5)>' |
| 355 | """ |
| 356 | def __nice__(self): |
| 357 | """str: a "nice" summary string describing this module""" |
| 358 | if hasattr(self, '__len__'): |
| 359 | # It is a common pattern for objects to use __len__ in __nice__ |
| 360 | # As a convenience we define a default __nice__ for these objects |
| 361 | return str(len(self)) |
| 362 | else: |
| 363 | # In all other cases force the subclass to overload __nice__ |
| 364 | raise NotImplementedError( |
| 365 | f'Define the __nice__ method for {self.__class__!r}') |
| 366 | |
| 367 | def __repr__(self): |
| 368 | """str: the string of the module""" |