python - TypeError: list indices must be integers, not RowProxy
问题描述
I make query like this in a function:
def get_artist_data(...):
sql = 'select * from artist where id in (' + ','.join(map(str, artist_ids)) + ')'
db_value = db.session.execute(sql).fetchall()
This is how db_value
looks like:
[(121", u'', 55, u'John Lennon', datetime.date(1940, 9, 9),...), (123, u'', 23, u'Paul McCartney', datetime.date(1942, 6, 17),...)]
I want to loop through db_value
:
for i in db_value:
yield {"artist_id": db_value[i][0],
"artist_name": db_value[i][3]}
This is what I get:
TypeError: list indices must be integers, not RowProxy
解决方案
也许:
for i in range(0,len(db_value)-1,1):
yield {"artist_id": db_value[i][0],
"artist_name": db_value[i][3]}
推荐阅读
- javascript - text/html blob 是 iframe 的来源,其中包含 html 和 JS 代码,会创建 mimetype 错误
- python - 列表索引必须是整数或切片,而不是我程序中的 str
- mongoose - MongooseError:操作 `blacklistScema.find()` 缓冲在 10000 毫秒后超时
- push-notification - Ionic 3 与 OneSignal 不兼容吗?
- flutter - 如何使用颤振获得通话帐户权限?
- firebase - 由于达到 Firestore 限制而扩大规模时
- python - 试图运行模块,但弹出此语法错误
- c - 按住一个键,然后按另一个键,停止按下原来的键
- cloudflare - 我可以在 Cloudflare 页面上托管静态 .json 文件吗?我想通过 REST 上传它们
- python - Python bs4 HTML 内容无意义