[Tutor] Initialize Class Variables by Dictionary ...
Damon Timm
damontimm at gmail.com
Sat Aug 29 22:31:57 CEST 2009
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():
... def __init__(self):
... for key in dict:
... self.key = dict[key]
...
>>> t = Test()
>>> t.test1
Traceback (most recent call last):
File "<console>", line 1, in <module>
AttributeError: Test instance has no attribute 'test1'
>>> t.key
'value3'
Can I do what I am dreaming of ?
Thanks,
Damon
More information about the Tutor
mailing list