All I'd like to do is print a single row of an sqlalchemy table row.
Say I have:
from sqlalchemy import Column, Integer, String
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class ATable(Base):
__tablename__ = 'atable'
id = Column(Integer, primary_key=True)
name = Column(String(255), nullable=False)
Then I'd like to output anything that looks like this:
id: 1
name: theRowName
Preferable without having to hard code in the table columns, i.e. more generally.
I've tried:
atable = Atable()
... #add some values etc.
print atable
print str(atable)
print repr(atable)
print atable.__table__.c
As well as thought about implementing __str__ and __repr__, but they again lack the generality request.
There are many questions on covering a table row into JSON, but that's not really what I want, I care more about the visual output - it doesn't need to be machine readable afterwards.
__str__and__repr__methods respectively to your model, if you wish to alter the representations.__str__and__repr__