I am coding (or rather trying to code) a game in python and I have following problem.
When I use loop this loop that should give me values from dictionaries(x.chest etc., every dict looks like that {'fire': 0.0, 'water': 0.0, 'acid': 0.0,'air': 0.0}):
for damag in (x.chest, x.stomach, x.lhand, x.rhand, x.lleg, x.rleg):
for value in damag.values():
print(value)
i get
AttributeError: 'function' object has no attribute 'values'
If i change the code to:
for damag in (x.chest, x.stomach, x.lhand, x.rhand, x.lleg, x.rleg):
for value in damag().values():
print(value)
it works but only partially. It returns values from x.chest and then gives an error:
TypeError: 'dict' object is not callable
I think that the solution to this problem must be easy, but there is flaw in my thinking so I can’t find it. I can solve this by doing separate loop for each dictionary but I think that this is not the best idea.
Clearly, your list of
xattributes is not homogeneous; at least one of the attributes you list there is a function, while at least one other is a dict.