Re: [sqlalchemy] Getting column data from result set with column name as a string.

2020-08-20 Thread Simon King
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):

Re: [sqlalchemy] Getting column data from result set with column name as a string.

2020-08-19 Thread Mike Bayer
__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

Re: [sqlalchemy] Getting column data from result set with column name as a string.

2020-08-18 Thread 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

Re: [sqlalchemy] Getting column data from result set with column name as a string.

2020-08-18 Thread Mike Bayer
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),

[sqlalchemy] Getting column data from result set with column name as a string.

2020-08-18 Thread Dale Preston
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