[英]Python :: passing a list as parameter
responses
in pyen
, a thin library for music data, returns dictionaries in this fashion: pyen
responses
,一个用于音乐数据的瘦库,以这种方式返回字典:
{u'id': u'AR6SPRZ1187FB4958B', u'name': u'Wilco'}
I'm looping through and printing artists: 我正在循环并打印艺术家:
response = en.get('artist/search', artist_location='Chicago')
artists = response['artists']
for artist in artists:
sys.stdout.write("song by {}\n".format(artist['name']))
but I'd like to pass a list of ids
here: 但是我想在这里传递一个
ids
列表:
response = en.get('song/search', artist_ids = ?) //pass a list here?
for song in response['songs']:
sys.stdout.write("\t{}\n".format(song['title']))
Is this possible? 这可能吗? How?
怎么样?
pyen
is a very thin wrapper, you should always check the EchoNest API docs directly. pyen
是一个非常薄的包装器,你应该总是直接检查EchoNest API文档。 According to the API documentation , the song/search
endpoint does not accept multiple artist_id
s. 根据API文档 ,
song/search
端点不接受多个artist_id
。
If you look at the Echo Nest API , you'll see that song search by artist_id doesn't support multiple params. 如果你看一下Echo Nest API ,你会发现artist_id的歌曲搜索不支持多个参数。
Thus, that's a restriction on pyen, as well, being a consumer of that API. 因此,这也是对pyen的限制,也是该API的消费者。
Instead, you'll have to print songs in a loop of requests: 相反,您必须在一系列请求中打印歌曲:
artist_ids = ['AR54RGR1187FB51D10', 'AR6SPRZ1187FB4958B', 'AR5KAA01187FB5AEB7']
for artist_id in artist_ids:
for song in en.get('song/search', artist_id=artist_id).get('songs', []):
sys.stdout.write("\t{}\n".format(song['title']))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.