简体   繁体   English

Python ::将列表作为参数传递

[英]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.

相关问题 在Python中传递不完整的参数列表 - Passing Incomplete Parameter List in Python 将python spark数据存储到列表中并作为参数传递 - Storing python spark data into a list and passing as parameter 传递列表并将其长度设置为 python 中的默认参数 - Passing a list and setting it length as a default parameter in python 在 python 中将列表作为参数传递时出现未定义错误 - undefined error when passing list as parameter in python 使用Python传递列表和字典类型参数 - Passing list and dictionary type parameter with Python Python:将列表作为参数传递,以便对实际列表进行排序 - Python: Passing a list as parameter so the actual list is sorted Spotify-将列表作为参数传递 - Spotify - passing a list as parameter Python字符串-将参数从列表传递给.__ contains__ - Python String - Passing parameter to .__contains__ from a list 将List作为参数传递给另一个方法,但是该方法在Python中将该参数接受为Tuple吗? - Passing List as an argument to another method, but the method accept the parameter as Tuple in Python? 在Python中将数组列表作为函数参数传递时如何解压和重塑数组列表 - How to unpack and reshape a list of arrays when passing it as function parameter in Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM