I'm trying to write a helper function in SqlAlchemy which lets me pass a row from a table and then it will print out the title of each column in that row along with the value stored in each column. The objective is to be able to print off all the attributes of entries without having to call each column individually, and without even needing to know what each column is called.
What I have so far came from this question. It looks like this:
def printModel(model):
columns = [m.key for m in model.__table__.columns]
for x in columns:
print x
someModel = SomeTable.query.get(someID)
printModel(someModel)
All that does so far is print off the names of the columns in that object. Is there a way I can make it print off the name of the columns and the value in each of those columns?
Thanks a lot, Alex