查询
SELECT leaveZoneVelocity, leaveZoneVelocityZ, leaveZoneVelocityXYZ
FROM stageentertimes WHERE player_id=? AND map_id=? ORDER BY duration ASC
代码:
leavestart_t1_all = [{u'leaveZoneVelocityZ': 0L, u'leaveZoneVelocityXYZ': 245L, u'leaveZoneVelocity': 245L}]
leavestart_t1 = leavestart_t1_all["leaveZoneVelocity"]
leavestart_t1 = leavestart_t1_all[3]
我得到了第一个leave_start_t1
TypeError: list indices must be integer
第二个:
List index out of range
希望你能帮助我,也许能给我一个解释。
最佳答案
您有一个包含一个字典的列表。索引列表,然后返回字典:
leavestart_t1 = leavestart_t1_all[0]["leaveZoneVelocity"]
这里leavestart_t1_all[0]
索引外部列表,返回包含的字典。
如果您使用的是 SQL 库,则可以使用 cursor.fetch_one()
来获取第一行,而不是使用 cursor.fetch_all()
然后需要建立索引。
关于python - 我如何从这个字符串中挑选?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28527654/