Hi,


I'm using sqlalchemy.ext.automap like so:


engine = create_engine(DATABASE_URL)

Base = automap_base()

Base.prepare(engine, reflect=True)

MediacloudStory = Base.classes.mediacloud_stories


session = Session(engine)

for mc_story in session.query(MediacloudStory).all():

    print(mc_story)


I expect to be able to run dict(mc_story) to get the result as a dictionary but 
I am unable to do so. I get this error:


TypeError: 'mediacloud_stories' object is not iterable


I am able to convert it to a dictionary using inspection though.


from sqlalchemy import inspect def object_as_dict(obj): return {c.key: 
getattr(obj, c.key) for c in inspect(obj).mapper.column_attrs}

The function above works fine.


It seems like dict(myobj) should be supported. 


Thanks,

Al

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to