from dict to member vars...?
Diez B. Roggisch
deetsNOSPAM at web.de
Thu Oct 14 13:58:57 EDT 2004
Christopher J. Bottaro wrote:
> Hello,
>
> Lets say I have a class instance with the following member vars: var1, x,
> size. Now lets say I have dict with the following keys: var1, x, size.
> Is there an easy way to *automatically* assign all the values in the dict
> to corresponding (member) vars of the same name as the dict keys?
d = dict(...)
for key, val in d.items():
setattr(o, key, val)
--
Regards,
Diez B. Roggisch
More information about the Python-list
mailing list