Newbie Q: dynamically assigning object attribute

Ben Wilson dausha at gmail.com
Thu Feb 9 20:41:55 EST 2006


I would like to dynamically assign object attributes:

dict = {
 a : 1,
 b : 2,
}

for key,val in dict :
  obj.key = val

To get:

print obj.a
1

I've googled to no effect, or maybe I'm needing to be hit with the
appropriately sized clue-by-four. Any assistance would be appreciated.

Regards,
Ben




More information about the Python-list mailing list