I have a bunch of tables in SQLAlchemy that I want to define __repr__
.
The standard convention seems to look like this:
def __repr__(self):
return "<TableName(id='%s')>" % self.id
This is all well and good for small tables. However, I have tables with 40+ columns. Is there a better way of constructing __repr__
such that I am not manually typing out a massive string?
My file housing all tables is called models.py
. One solution I thought about was making a method _create_repr_string
in models.py
that takes care of auto-generating the string for __repr__
to return. I am wondering if there is a more standard way to create __repr__
.