Last active
February 8, 2018 20:46
-
-
Save pathunstrom/d60748cfd7824e2c1552c00f57b25cc4 to your computer and use it in GitHub Desktop.
A very simple auto repr
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 Example: | |
def __repr__(self): | |
val = lambda x: f"{x}={getattr(self, x)!r}" | |
parameters = ", ".join(val(param) for param in signature(type(self)).parameters) | |
return f"{type(self).__name__}({parameters})" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment