2012-07-15 472 views
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 

我認爲,要解決這個問題必須是容易的,但有缺陷在我的思想,所以我不能找到它。我可以通過爲每個字典分別循環來解決這個問題,但我認爲這不是最好的主意。

回答

4

顯然,您的x屬性列表不是同質的;至少一個你列出的屬性有一個函數,而至少有一個是字典。

+0

是的,我在我的代碼中犯了一個錯誤。我把所有的東西都改成了我的作品。非常感謝你。 – L22A2 2012-07-15 09:38:26

相關問題