Skip to content

Instantly share code, notes, and snippets.

@stuaxo
Created July 22, 2020 22:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stuaxo/953a506a3adf183aec110b0660885133 to your computer and use it in GitHub Desktop.
Save stuaxo/953a506a3adf183aec110b0660885133 to your computer and use it in GitHub Desktop.
Python class repr that outputs class members.
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