Python中model转dict
2016-11-25 19:11
148 查看
SQLAlchemy
在query出来的行信息object中有一个dict变量,这个变量存储了字典信息for u in session.query(User).all(): print u.__dict__
但是这个变量会多一个属性’_sa_instance_state’,所以还需要在转换字典之后把这个属性去掉:
dictret = dict(row.__dict__); dictret.pop('_sa_instance_state', None)
参考
http://stackoverflow.com/questions/1958219/convert-sqlalchemy-row-object-to-python-dict相关文章推荐
- python model对象转为dict数据
- python的dict,set,list,tuple应用
- Python源码剖析[12] —— 字典对象PyDictObject(1)
- python中的dict.
- python dict的list排序
- python assert dict 断言@对比@之递归断言
- python glob model
- python - 基础类型 - dict
- python基础31[list+tuple+set+dict+str+file的成员方法]
- python的list,dict,tuple比较和应用
- Python源码剖析[13] —— 字典对象PyDictObject(2)
- python dict
- Python从两个List构造Dict
- django配置apache model_python
- python学习3-使用dict
- python 中参数传递 * 和 ** 的问题,以 tuple和dict方式传递参数
- python整理二——dict的list排序
- Python 跟 ArcGIS断了联系……Model的py脚本无法运行
- Python中的Dict对象(Python 源码剖析第五章)
- C++ python 交互之 python.dict to c++ map