"Extracting" a dictionary

Konstantin Veretennicov kveretennicov at yahoo.com
Fri May 21 08:23:21 EDT 2004


Peter Otten <__peter__ at web.de> wrote in message news:<c8inoe$n0c$05$1 at news.t-online.com>...
> 
> >>> class AttrDict:
> ...     def __init__(self, d):
> ...             self.__dict__.update(d)
> ...
> >>> d = AttrDict({"foo": 23, "bar": 42})
> >>> d.bar
>  42
> >>> d.foo *= 2
> >>> d.__dict__
>  {'foo': 46, 'bar': 42}
> >>> del d.foo
> >>> d.__dict__
>  {'bar': 42}
> >>>
> 
> A standard trick, by the way. Can't think of the right google keywords right
> now, so I use another standard trick and leave finding them as an excercise
> to the reader :-)
> 
> Peter


http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52308  (Bunch class)
http://www.norvig.com/python-iaq.html  (Struct class)

- kv



More information about the Python-list mailing list