vendredi 21 avril 2017

Python Issues with a Class

I am having issues with my below class. I keep getting the below traceback, butI am not sure were I am going wrong. I am expecting to see a dictionary with photo tags. Any help would be great.

Traceback:

File "project.py", line 231, in <module>
    new_photo = Photo(result_get_photo_data)
  File "project.py", line 228, in __init__
    for diction in photo_diction["photo"]["tags"]["tag"]:
TypeError: list indices must be integers, not st

My Code:

class Photo(object): 
    def __init__(self,photo_diction):
        self.tags = []
        for diction in photo_diction["photo"]["tags"]["tag"]:
            return self.tags.append(diction)

new_photo = Photo(result_get_photo_data)
print new_photo.tags






Comments
0 Comments

0 commentaires:

Enregistrer un commentaire