我正在尝试从Web服务获取一些信息,并将其放入循环中,但是,我陷入了这个令人讨厌的错误中。
for game in r['result']['data']:
print("id:{} \n Name {}".format(game['id'], game['name']))
lista.append(**game)
此列表应从函数中返回,但我不能将此错误的内容抄送!
id:937296541
Name Dead Zombie Drop Crush - Military Training Adventure
Traceback (most recent call last):
File "games_info.py", line 195, in <module>
cli()
File "C:\Users\Guilherme\AppData\Local\Programs\Python\Python37\lib\site-packages\click\core.py", line 764, in __call__
return self.main(*args, **kwargs)
File "C:\Users\Guilherme\AppData\Local\Programs\Python\Python37\lib\site-packages\click\core.py", line 717, in main
rv = self.invoke(ctx)
File "C:\Users\Guilherme\AppData\Local\Programs\Python\Python37\lib\site-packages\click\core.py", line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "C:\Users\Guilherme\AppData\Local\Programs\Python\Python37\lib\site-packages\click\core.py", line 555, in invoke
return callback(*args, **kwargs)
File "games_info.py", line 184, in cli
listaTot = dumpb(dti, dtf, token)
File "games_info.py", line 134, in dumpb
lista.append(**game)
AttributeError: 'dict' object has no attribute 'append'
实际上列表被伪装为由类定义的对象的列表。
gameVar = Game(game['age_rating'], game['average_user_rating'],
game['current_version_release_date'], game['description'],
game['developer'], game['genres'], game['icon_url'],
game['id'], game['inapp_purchases'], game['languages'],
game['name'], game['original_release_date'], game['price'],
game['primary_genre'], game['size'], game['subtitle'],
game['url'], game['user_rating_count'])
lista.append(gameVar)
lista是字典,没有附加功能。您可以将其更改为列表,只需定义如下即可。lista = []
AttributeError:'dict'对象没有属性'append'。您已将'lista'定义为字典,没有附加功能。
您可以将其定义为::
lista = []
lista.append(**game)