Last active
April 8, 2022 10:57
-
-
Save laminko/4303e68758d7940ae3ce2373d6e12fe4 to your computer and use it in GitHub Desktop.
Printable representation of an object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from inspect import signature | |
class BaseClass: | |
def __repr__(self) -> str: | |
fields = signature(self.__init__).parameters | |
values = ', '.join(repr(getattr(self, f)) for f in fields) | |
return f'{type(self).__name__}({values})' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment