joalla / discogs_client

Continuation of the "Official Python Client for the Discogs API"
https://python3-discogs-client.readthedocs.io
Other
310 stars 50 forks source link

python3 cant view contents of <list> #111

Closed MartinBarker closed 2 years ago

MartinBarker commented 2 years ago

I am using a python discogs api package to retrieve a music playlist from online. I need to iterate through this list to view all results, but no matter what I try I get a typeerror saying 'list object is not iterable / subscriptable'

d = discogs_client.Client('ExampleApplication/0.1', user_token=DISCOGS_TOKEN)
results = d.list('117796')
print('results=')
print(results)
print(results[0])

you can see I am returning a list just fine, but if I try to view the contents of said list, I get an error

results=
<List '117796' 'Ron Hardy @ Music Box'>
Traceback (most recent call last):
  File "twitter_bot.py", line 52, in <module>
    artist = results[0].artists[0]
TypeError: 'List' object is not subscriptable
JOJ0 commented 2 years ago

We are talking about a Discogs List object here and not a Python list right?

I dont know by heart and am afk right now but can suggest you try figuring out what the objects props and methods are with print(dir(results)) HTH

AnssiAhola commented 2 years ago

That seems to be an List object. That has an property called items which is a Python list of ListItem objects

try

print(results.items[0])
JOJ0 commented 2 years ago

Hi @MartinBarker is your question anwered? Should we close this issue?