原文链接: http://www.kylin-ux.com/2017/04/26/database-package-sqlalchemy-sqlalchemy.ext.declarative.api.DeclarativeMeta转dict

1
2
def to_dict(alchemy_table):
return {c.name: getattr(alchemy_table, c.name, None) for c in alchemy_table.__table__.columns}

使用

1
print(to_dict(table))

table为query返回值(DeclarativeMeta类型)