Re: [Tutor] Initialize Class Variables by Dictionary ...

2009-08-29 Thread Kent Johnson
On Sat, Aug 29, 2009 at 6:30 PM, Damon Timm wrote: > Hey!  I am a newbie too but it works for me: > class Test(object): > ...   def __init__(self,dict): > ...     for key in dict: > ...       self.__setattr__(key,dict[key]) Use the setattr() builtin: setattr(self, key, dict[key]} or just d

Re: [Tutor] Initialize Class Variables by Dictionary ...

2009-08-29 Thread Damon Timm
Hey! I am a newbie too but it works for me: >>> class Test(object): ... def __init__(self,dict): ... for key in dict: ... self.__setattr__(key,dict[key]) ... >>> t = Test() >>> t.test1 'hi there' >>> t.test2 'not so much' >>> t.test3 'etc' Thanks! On Sat, Aug 29, 2009 at 4:59 PM, M

Re: [Tutor] Initialize Class Variables by Dictionary ...

2009-08-29 Thread Mac Ryan
On Sat, 2009-08-29 at 16:31 -0400, Damon Timm wrote: > Hi again - thanks for your help with my question early today (and last > night). Tried searching google for this next question but can't get > an answer ... here is what I would like to do (but it is not working) > ... > > >>>dict = {'test1':

[Tutor] Initialize Class Variables by Dictionary ...

2009-08-29 Thread Damon Timm
Hi again - thanks for your help with my question early today (and last night). Tried searching google for this next question but can't get an answer ... here is what I would like to do (but it is not working) ... >>>dict = {'test1': 'value1', 'test2': 'value2', 'test3': 'value3'} >>> class Test()