B
B
bogdan_242016-01-14 01:58:47
Python
bogdan_24, 2016-01-14 01:58:47

Why is there an error when calling the method?

TypeError: 'int' object is not subscriptable when calling self.getAudioInfo() on the line self.url = self.listOfAudio[self.trackId]['url']. Help!

class Track():
    def getAudioInfo(self):
        self.url = self.listOfAudio[self.trackId]['url']
        self.artist = self.listOfAudio[self.trackId]['artist']
        self.title = self.listOfAudio[self.trackId]['title']
        return '{0} - {1}'.format(self.artist, self.title)

    def __init__(self, trackId, uid=124366326):
        self.listOfAudio = vkapi.audio.get(owner_id=uid)
        print(self.listOfAudio)
        self.trackId = trackId
        self.getAudioInfo()
track1 = Track(0)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly, 2016-01-14
@bogdan_24

Here you have a line: print(self.listOfAudio). Obviously for debugging has been added. What does she output?
The point is that the self.listOfAudio[self.trackId]['url'] line expects listOfAudio to be a list of dictionaries, but it's actually something else: a list of numbers or just a number. Because the error 'int' object is not subscriptable , implies that you are trying to refer to a number as a "container". That is, it is equivalent to such a record: 100[1]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question