Bunch getitem always returns a Bunch
Created by: kevinkuns
This modifies Bunch.__getitem__
so that a Bunch
is always returned even if the value is a dictionary. For example, if
a = Bunch(b=dict(x=1, y=2))
then a.b
is a Bunch
instead of dict
. This is useful for looping through elements, especially in conjunction with walk
. This change is especially useful for the construction
from wield.utilities.file_io import load
data = Bunch(load(filename))
since, unlike with gwinc.Struct
, Bunch
does not recursively make Bunch
's for nested dict
's.
To make the value always be a Bunch
with iterators, the __iter__
method would still need to be modified however.