Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to call method on dict, getting AttributeError: 'dict' object attribute 'update' is read-only

I have no idea what is wrong or what causes the error:

AttributeError: 'dict' object attribute 'update' is read-only

on the following code:

map = []
point1back = {}
point1fwd = {}
point1back.update = {'nextHop':point1Fwd, 'direction':1, 'distance':0}
point1fwd.update = {'nextHop':point1Fwd, 'direction':3, 'distance':160}
map.append(point1back)
map.append(point1fwd)
like image 611
Duke Avatar asked Apr 23 '18 23:04

Duke


People also ask

How do I fix AttributeError dict object has no attribute append?

The Python "AttributeError: 'dict' object has no attribute 'append'" occurs when we try to call the append() method on a dictionary. To solve the error, use bracket notation to add a key-value pair to a dict or make sure to call the append() method on a list.

What is __ dict __ in Python?

The __dict__ in Python represents a dictionary or any mapping object that is used to store the attributes of the object. They are also known as mappingproxy objects. To put it simply, every object in Python has an attribute that is denoted by __dict__.

Does Iteritems have no attribute?

The Python "AttributeError: 'dict' object has no attribute 'iteritems'" occurs because the iteritems() method has been removed in Python 3. To solve the error, use the items() method, e.g. my_dict. items() , to get a view of the dictionary's items.


1 Answers

dict.update is a method, not a variable you can assign a value to. Try this instead:

point1back.update({'nextHop':point1Fwd, 'direction':1, 'distance':0})
like image 116
jpp Avatar answered Nov 04 '22 19:11

jpp