On May 14, 5:49 am, Gunter Henriksen <gunterhenrik...@gmail.com>
wrote:
> Presuming it is very common to have objects created
> on the fly using some sort of external data
> definitions, is there an obvious common standard
> way to take a dict object and create an object
> whose attribute names are the keys from the dict?

I've always liked this approach, which I first saw in a post by Alex
Martelli:

>>> class Bunch(object):
...     def __init__(self, **kwargs):
...         self.__dict__.update(kwargs)
...
>>> b = Bunch(a=1,b=2,c=3)
>>> b.a
1
>>> b.b
2
>>> b.d = 22
>>> b.d
22


Elegant.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to