Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python list can´t append: Syntax Error: append() takes no keyword arguments

I´m trying get some info from a web service and put this in a loop, but, im stuck in this anoying error.

 for game in r['result']['data']:
        print("id:{} \n Name {}".format(game['id'], game['name']))
        lista.append(**game)

this list should be returned from the function, but i cant bc of this error!

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'

Actually list is pretended to be a list of objects defined by a class.

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)
like image 331
Guilherme Cesar Avatar asked Jul 19 '26 19:07

Guilherme Cesar


1 Answers

The lista is a dict, which don't have append function. You can change it to a list, just define like this. lista = []

like image 69
TAN Avatar answered Jul 22 '26 10:07

TAN



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!