1
我正在编写(或者试图编写代码)python游戏,我有以下问题。 当我使用循环这个循环,应该给我的字典值(x.chest等,每一个字典看起来像{'fire': 0.0, 'water': 0.0, 'acid': 0.0,'air': 0.0}
):AttributeError:'function'object has no attribute'values'
for damag in (x.chest, x.stomach, x.lhand, x.rhand, x.lleg, x.rleg):
for value in damag.values():
print(value)
我得到
AttributeError: 'function' object has no attribute 'values'
如果我更改代码到:
for damag in (x.chest, x.stomach, x.lhand, x.rhand, x.lleg, x.rleg):
for value in damag().values():
print(value)
它的工作原理,但只是部分。它从x.chest返回值,然后给出了一个错误:
TypeError: 'dict' object is not callable
我认为,要解决这个问题必须是容易的,但有缺陷在我的思想,所以我不能找到它。我可以通过为每个字典分别循环来解决这个问题,但我认为这不是最好的主意。
是的,我在我的代码中犯了一个错误。我把所有的东西都改成了我的作品。非常感谢你。 – L22A2 2012-07-15 09:38:26