By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,095 Members | 1,658 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,095 IT Pros & Developers. It's quick & easy.

dynamicly updating an objects fields

P: n/a

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?

Aug 31 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
kyle.tk wrote:
I want to make a function that will work like this:

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


This function already exists in python.
It is called settattr.

Regards
Uwe
Aug 31 '05 #2

P: n/a
Uwe Lauth wrote:
kyle.tk wrote:
I want to make a function that will work like this:

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


This function already exists in python.
It is called settattr.


Or rather setattr.

--
Robert Kern
rk***@ucsd.edu

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter

Aug 31 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.