Skip to content

Instantly share code, notes, and snippets.

@laminko
Last active April 8, 2022 10:57
Show Gist options
  • Save laminko/4303e68758d7940ae3ce2373d6e12fe4 to your computer and use it in GitHub Desktop.
Save laminko/4303e68758d7940ae3ce2373d6e12fe4 to your computer and use it in GitHub Desktop.
Printable representation of an object
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