Skip to content

Instantly share code, notes, and snippets.

@Den1al
Den1al / generic-repr.py
Last active February 13, 2018 16:58
A decorator that injects a generic repr function to a class
# author: @Daniel_Abeles
# date: 23/12/2017
def inject_generic_repr(cls):
""" Injects a generic repr function """
def generic_repr(that):
class_items = [f'{k}={v}' for k, v in that.__dict__.items()]
return f'<{that.__class__.__name__} ' + ', '.join(class_items) + '>'