Search code examples
pythondictionaryattributeerror

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)

Solution

  • 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})