- Copy dictionary entries to attributes
Alex Martelli
aleaxit at yahoo.com
Sun Feb 19 02:30:54 EST 2006
Ben Wilson <dausha at gmail.com> wrote:
> Perhaps:
>
> def dictionary_make_attributes(self, settings):
> for k,v in settings:
> setattr(self, k, v)
This is a very general solution and will work for all kinds of objects
with settable attributes, even if some of the attributes are properties,
slots or weirder descriptors yet.
For plain vanilla class instances, though,
self.__dict__.update(settings)
may be sufficient.
Alex
More information about the Python-list
mailing list