Created
July 22, 2020 22:05
-
-
Save stuaxo/953a506a3adf183aec110b0660885133 to your computer and use it in GitHub Desktop.
Python class repr that outputs class members.
This file contains hidden or 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
def class_repr(self): | |
""" | |
Default class repr that outputs the content of a class. | |
Usage: | |
>>> class A: | |
... __repr__ = class_repr | |
... | |
""" | |
members = ', '.join({f'{k}={v}' | |
for k, v in | |
self.__dict__.items()}) | |
return f'{self.__class__.__name__}({members})' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment