dynamicly updating an objects fields
kyle.tk
kyle.tk at gmail.com
Wed Aug 31 01:20:20 EDT 2005
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?
More information about the Python-list
mailing list