Fragkiller
Fragkiller

Reputation: 609

How can I pick from this string?

Query

SELECT leaveZoneVelocity, leaveZoneVelocityZ, leaveZoneVelocityXYZ
FROM stageentertimes WHERE player_id=? AND map_id=? ORDER BY duration ASC

Code:

leavestart_t1_all = [{u'leaveZoneVelocityZ': 0L, u'leaveZoneVelocityXYZ': 245L, u'leaveZoneVelocity': 245L}]

leavestart_t1 = leavestart_t1_all["leaveZoneVelocity"]

leavestart_t1 = leavestart_t1_all[3]

I get for the first leave_start_t1

TypeError: list indices must be integer

and for the 2nd one:

List index out of range

Hope you can kinda help me, and maybe giving me an explanation.

Upvotes: 1

Views: 24

Answers (1)

Martijn Pieters
Martijn Pieters

Reputation: 1125058

You have a list with one dictionary. Index the list, then the dictionary returned:

leavestart_t1 = leavestart_t1_all[0]["leaveZoneVelocity"]

Here leavestart_t1_all[0] indexes the outer list, returning the dictionary contained.

If you are using a SQL library, instead of using cursor.fetch_all() you can use cursor.fetch_one() to just get that first row, and no indexing is then required.

Upvotes: 1

Related Questions