dynamicly updating an objects fields




I want to make a function that will work like this:

def updateField(object, fieldName, newValue):
object.fieldName = newValue

fieldName could be anything, the list of objects fields will grow as my
project goes on and i want to reuse the same code without adding more
if statements to it

this is the only way I can see doing it right now:

def updateField(object, fieldName, newValue):
if fieldName = 'name':
nodeDict[nodeID].name = newValue
if fieldName = 'color':
nodeDict[nodeID].color = newValue
..many more if's..

is the top example possible?

.



Relevant Pages