【发布时间】:2019-08-04 15:37:09
【问题描述】:
如何迭代:
A:
A1: 1000
A2:
A2A:
A2A1: 100
A2A2: 250
A2A3: 250
A2B:
A2B1: 100
A2B2: 300
A3:
A3A:
A3A1:
A3A1A: 200
A3A1B: 100
# There could be more values
我想在同一个地方添加A3A1A和A3A1B的值和其他值
我尝试了以下方法:
with open("foobar.yml", 'r') as stream:
foobar = yaml.load(stream)
end_value = 0
for one_value in foobar["A1"]["A3"]["A3A"] ["A3A1"][*]:
end_value = end_value + one_value
但这不起作用
【问题讨论】: