I really have no idea what's going on here -- let me outline the code.
I'm pulling data from the SFG WorldCup API.
Sample output from the API from earlier today:
[
{
"match_number": 26,
"location": "Arena da Baixada",
"datetime": "2014-06-20T19:00:00.000-03:00",
"status": "in progress",
"home_team": {
"country": "Honduras",
"code": "HON",
"goals": 1
},
"away_team": {
"country": "Ecuador",
"code": "ECU",
"goals": 2
},
"winner": null,
"home_team_events": [
{
"id": 290,
"type_of_event": "yellow-card",
"player": "Bernardez",
"time": "7"
},
{
"id": 291,
"type_of_event": "goal",
"player": "Costly",
"time": "31"
},
{
"id": 294,
"type_of_event": "substitution-in halftime",
"player": "J.C. Garcia",
"time": "46"
},
{
"id": 297,
"type_of_event": "substitution-in",
"player": "M. Martinez",
"time": "71"
},
{
"id": 301,
"type_of_event": "substitution-in",
"player": "M. Chavez",
"time": "83"
},
{
"id": 293,
"type_of_event": "yellow-card",
"player": "Bengtson",
"time": "453"
}
],
"away_team_events": [
{
"id": 292,
"type_of_event": "goal",
"player": "E. Valencia",
"time": "34"
},
{
"id": 295,
"type_of_event": "yellow-card",
"player": "A. Valencia",
"time": "57"
},
{
"id": 296,
"type_of_event": "goal",
"player": "E. Valencia",
"time": "65"
},
{
"id": 298,
"type_of_event": "yellow-card",
"player": "E. Valencia",
"time": "73"
},
{
"id": 299,
"type_of_event": "yellow-card",
"player": "Montero",
"time": "80"
},
{
"id": 300,
"type_of_event": "substitution-in",
"player": "Mendez",
"time": "82"
},
{
"id": 302,
"type_of_event": "substitution-in",
"player": "Gruezo",
"time": "83"
}
]
}
]
With this data, my problem is that getting data in the for loop works, but in a while loop below it doesn't.
resp
is the response from the api...
for jogo in resp.json():
score = jogo['home_team']['goals']
jogo = resp.json()
while True:
newscore = int(jogo['home_team']['goals'])
The actual code is a little different (the jogo['home_team']['goals']
in the while loop is in an if
statement, but this is the basic skeleton of it.
The error I get is on the one in the while
, and it says TypeError: list indices must be integers, not str
I'm not sure if it's relevant that I'm comparing it to an integer (I have it wrapped in an int()
).
What's causing this, and why isn't it being called on the first one.
Thanks!
evamvid
PS let me know if this doesn't make any sense =)