2017-07-30 90 views
0

我期待回路印刷同义词对每个项目从我的名单从循环使用Python unirest列表

myList = ["First", "Second", "Third"] 

尝试没有成功几个循环的方法,请大家帮忙

手动打印出来1通过1命令是

response = unirest.get("https://wordsapiv1.p.mashape.com/words/first/synonyms", headers={ "X-Mashape-Key": "**MY -Mashape-Key", "Accept": "application/json" }) 

response.body < ===这将打印字同义词 “第一”

如何循环打印我的列表中的所有单词的正文? 感谢

+0

你可以显示示例json输出吗?我们没有这个网站的任何API密钥。 – aristotll

+0

我可以私下分享你一个私人密钥,以测试你是否想要,我真的很喜欢这个。谢谢 – totheM

回答

0

试试这个

for word in myList 
    response = unirest.get("https://wordsapiv1.p.mashape.com/words/" + word + "/synonyms", headers={ "X-Mashape-Key": "API_KEY", "Accept": "application/json" }) 
    print response.body 

我不知道Python,但其文档,似乎它应该工作。

+0

这是我尝试的第一个命令,但它说TypeError:不能连接'str'和'list'对象 – totheM

+0

@totheM错误意味着'word'是一个列表对象。所以你应该检查'myList'是否是列表的列表。 – aristotll

+0

这主要是我的错误尝试unirest.post而不是unirest.get – totheM