Python AttributeError: ‘dict’ object has no attribute ‘append’

Like the error message suggests, dictionaries in Python do not provide an append operation.

You can instead just assign new values to their respective keys in a dictionary.

mydict = {}
mydict['item'] = input_value

If you’re wanting to append values as they’re entered you could instead use a list.

mylist = []
mylist.append(input_value)

Your line user['areas'].append[temp] looks like it is attempting to access a dictionary at the value of key 'areas', if you instead use a list you should be able to perform an append operation.

Using a list instead:

user['areas'] = []

On that note, you might want to check out the possibility of using a defaultdict(list) for your problem. See here

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)