Getting a dictionary from an object
thanos at sians.org
Sat Jul 23 10:48:27 CEST 2005
I would like to have a quick way to create dicts from object, so that a
call to foo['bar'] would return obj.bar.
The following works, but I would prefer to use a built-in way if one
exists. Is there one?
Thanks in advance.
A dictionary d with an object attached to it,
which treats d['foo'] as d.obj.foo.
def __init__(self, obj):
self.obj = obj
def __getitem__(self, key):
Thanos Tsouanas .: My Music: http://www.thanostsouanas.com/
http://thanos.sians.org/ .: Sians Music: http://www.sians.org/
More information about the Python-list