Skip to content

Instantly share code, notes, and snippets.

from django.template import engines
class ReprMixin(object):
TEMPLATE = """<{{ class }}{% for field, value in fields_values %}
{{ field }}={{ value }}{% endfor %}>"""
def __repr__(self):
django_engine = engines['django']
template = django_engine.from_string(self.TEMPLATE)
"""
README:
Side Note:
I've never used attrs before, so thought it would be fun to try them out
see https://glyph.twistedmatrix.com/2016/08/attrs.html for an explanation of attrs
Runtime Complexity:
I originaly wrote as nexted for loops, which is O(n^2), but switched to
"""
____ ____ _____
| _ \| _ \| ___|
| | | | |_) | |
| |_| | _ <| _|
|____/|_| \_\_|
_____ _ _____ _ _ ___ _ _ _
|_ _(_)_ __ ___ |_ _| __(_) ___| | _____ ( _ ) | | | | __ _ ___| | _____
| | | | '_ \/ __| | || '__| |/ __| |/ / __| / _ \/\ | |_| |/ _` |/ __| |/ / __|