我正在学习使用Python和API(特别是这个世界杯API,http://www.kimonolabs.com/worldcup/explorer)
JSON数据如下所示:
[
{
"firstName": "Nicolas Alexis Julio",
"lastName": "N'Koulou N'Doubena",
"nickname": "N. N'Koulou",
"assists": 0,
"clubId": "5AF524A1-830C-4D75-8C54-2D0BA1F9BE33",
"teamId": "DF25ABB8-37EB-4C2A-8B6C-BDA53BF5A74D",
"id": "D9AD1E6D-4253-4B88-BB78-0F43E02AF016",
"type": "Player"
},
{
"firstName": "Alexandre Dimitri",
"lastName": "Song-Billong",
"nickname": "A. Song",
"clubId": "35BCEEAF-37D3-4685-83C4-DDCA504E0653",
"teamId": "DF25ABB8-37EB-4C2A-8B6C-BDA53BF5A74D",
"id": "A84540B7-37B6-416F-8C4D-8EAD55D113D9",
"type": "Player"
},
]
Run Code Online (Sandbox Code Playgroud)
我只是想在这个API中打印所有firstNames.这就是我所拥有的:
import urllib2
import json
url = "http://worldcup.kimonolabs.com/api/players?apikey=xxx"
json_obj = urllib2.urlopen(url).read
readable_json = json.dumps(json_obj)
playerstuff = readable_json['firstName']
for i in playerstuff:
print i['firstName']
Run Code Online (Sandbox Code Playgroud)
但是当我运行它时,我得到错误"......第8行,在...... TypeError:列表索引必须是整数,而不是str"
我已经四处寻找解决方案,但似乎在更深入的"API"问题中找到了问题,我还没有完全理解它,所以对我需要做的任何帮助或解释都会很棒.谢谢!
我正在尝试安装pandas,pip install pandas但是当我这样做时,我收到错误:
命令python setup.py egg_info失败,错误代码1在c:\ users [用户名]\appdata\local\temp\pip_build_ [用户名]\pandas
我按照这里给出的答案安装,ez_setup.py没有发生任何事故,但在做的时候仍然会收到错误pip install pandas.
感谢您的帮助,如果我能提供更多信息,请告诉我.
我试图找出为什么我不能让它运行正常.我只想要用户输入四个,并在最后运行计算.
#include <stdio.h>
#include <math.h>
int main(){
double amount; /* amount on deposit */
double principal; /* what's the principal */
double rate; /* annual interest rate */
int year; /* year placeholder and no. of total years */
int yearNo;
printf("What is the principal? ");
scanf("%d", &principal);
printf("What is the rate (in decimal)? ");
scanf(" .2%d", &rate);
printf("What is the principal? ");
scanf(" %d", &principal);
printf("How many years? ");
scanf(" %d\n", yearNo);
printf("%4s%21s\n", "Year", "Amount on deposit");
/* calculate …Run Code Online (Sandbox Code Playgroud)