【发布时间】:2016-05-31 00:38:00
【问题描述】:
使用bunch,可以递归使用Bunch吗?
例如:
from bunch import Bunch
b = Bunch({'hello': {'world': 'foo'}})
b.hello
>>> {'world': 'foo'}
所以,很明显:
b.hello.world
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-5-effaad77643b> in <module>()
----> 1 b.hello.world
AttributeError: 'dict' object has no attribute 'world'
我知道我能做到……
b = Bunch({'hello': Bunch({'world': 'foo'})})
...但这太糟糕了。
【问题讨论】: