我刚刚完成了一些在线教程,并且正在尝试使用Discogs Api
我的代码如下:
import discogs_client as discogs
discogs.user_agent = '--' #i removed it
artist_input = raw_input("Enter artist\'s name : ")
artist = discogs.Artist(artist_input)
if artist._response.status_code in (400, 401, 402, 403, 404):
print "Sorry, this artist %s does not exist in Discogs database" % (artist_input)
elif artist._response.status_code in (500, 501, 502, 503) :
print "Server is a bit sleepy, give it some time, won\'t you ._."
else:
print "Artist : " + artist.name
print "Description : " + str(artist.data["profile"])
print "Members :",
members = artist.data["members"]
for index, name in enumerate(members):
if index == (len(members) - 1):
print name + "."
else:
print name + ",",
我想使用的列表格式是这样的:
[<MasterRelease "264288">, <MasterRelease "10978">, <Release "4665127">...
我想用 MasterRelease 隔离那些,所以我可以得到他们的 id
我尝试了类似的东西
for i in artist.releases:
if i[1:7] in "Master":
print i
或者
for i in thereleases:
if i[1:7] == "Master":
print i
我当然错过了一些东西,但它让我感到困惑,因为我可以做到这一点
newlist = ["<abc> 43242"]
print newlist[0][1]
在这种情况下
thereleases = artist.releases
print thereleases[0][1]
我明白了
TypeError: 'MasterRelease' object does not support indexing
随意指出有关代码的任何内容,因为我对 python 的了解还很有限。