- Copy dictionary entries to attributes
Ilias Lazaridis
ilias at lazaridis.com
Tue Feb 21 06:27:59 EST 2006
Alex Martelli wrote:
> Ben Wilson <dausha at gmail.com> wrote:
>
>> Perhaps:
>>
>> def dictionary_make_attributes(self, settings):
>> for k,v in settings:
>> setattr(self, k, v)
for k,v in settings.items()
> 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
this is the construct I was looking for.
see it active:
http://pudge.lesscode.org/trac/changeset/118
http://pudge.lesscode.org/trac/ticket/16
.
--
http://lazaridis.com
More information about the Python-list
mailing list