If you want to get an attribute of an object where the name of the
attribute is variable, you can use the getattr function:
attrname = "lastname"
column = getattr(User, attrname)
for item in session.query(column):
print(item)
or:
attrname = "lastname"
for user in session.query(User):
__table__ is public (private would be a single or double underscore prefix
only), but also you could use inspect(cls).column_attrs:
https://docs.sqlalchemy.org/en/13/orm/mapping_api.html?highlight=column_attrs#sqlalchemy.orm.Mapper.column_attrs
On Wed, Aug 19, 2020, at 1:22 AM, Dale Preston
Thanks. The label is an interesting option; I'll look into that.
On a StackOverflow thread, I got *row.__table__.columns* which I can
iterate over and test the key, allowing me to get the column I need but I
have to loop through all the columns until I find the one I want for each
row because
On Tue, Aug 18, 2020, at 5:20 PM, Dale Preston wrote:
> I'm using sqlalchemy 1.3.18. I'm trying to write an app that looks at data
> from an ORM declarative table without necessarily knowing the table
> definition.
>
> What I am looking for is a way to get a single object (row in resultSet),
I'm using sqlalchemy 1.3.18. I'm trying to write an app that looks at data
from an ORM declarative table without necessarily knowing the table
definition.
What I am looking for is a way to get a single object (row in resultSet),
having the name of column[1] is "lastname", and having