converting dict to object
Gabriel Genellina
gagsl-py at yahoo.com.ar
Fri Dec 1 21:08:09 EST 2006
At Friday 1/12/2006 22:48, rieh25 wrote:
>If I have a dictionary such as:
>
>d = {'a' : 1, 'b' : 2}
>
>is there a way to convert it into an object o, such as:
>
>o.a = 1
>o.b = 2
>>> class X(object):
... def __init__(self, d): self.__dict__.update(d)
...
>>> d = {'a' : 1, 'b' : 2}
>>> o=X(d)
>>> o.a
1
>>> o.b
2
>>>
--
Gabriel Genellina
Softlab SRL
__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
More information about the Python-list
mailing list