「4.18 名前のついたアイテム群を集めておく」より抜粋.こんな使い方ができるんですね.辞書なのに、辞書のキー(文字列)をプロパティのようにして変数にアクセスできます.
class d(dict):
__getattr__ = dict.__getitem__
__setattr__ = dict.__setitem__
__delattr__ = dict.__delitem__
>>> d>>> ddd = d()
>>> ddd
{}
>>> ddd['a'] = [1,2,3]
>>> ddd
{'a': [1, 2, 3]}
>>> ddd.a
[1, 2, 3]
>>> dir(ddd)
['__class__', '__cmp__', '__contains__', '__delattr__', '__delitem__', '__dict__', '__doc__', '__eq__', ...]
>>> ddd.keys()
['a']
>>> ddd.b = {}
>>> ddd
{'a': [1, 2, 3], 'b': {}}
>>> ddd.b
{}
>>> ddd['b']
{}
>>> ddd.__class__>>> ddd.__class__.d
Traceback (most recent call last):
File "", line 1, in
AttributeError: type object 'd' has no attribute 'd'
>>> ddd.values()
[[1, 2, 3], {}]
>>> ddd.items()
[('a', [1, 2, 3]), ('b', {})]
>>> dict(ddd.items())
{'a': [1, 2, 3], 'b': {}}
>>>