我试图玩这个游戏,然后打开所有.Bat文件和虚拟.Bat文件说这个......
File "toontown\toonbase\ToonBase.py", line 78, in __init__
res = ratios[nativeIndex + 1][0]
TypeError: 'float' object has no attribute '__getitem__'
任何人都可以帮我解决这个问题吗?谢谢你的答案
谢谢大家的答案,这是ToonBase.py的代码
width = float(res[0])
height = float(res[1])
ratio = round(width / height, 2)
self.resDict.setdefault(ratio, []).append(res)
我也发现在代码中稍微浮动了对不起我不是这方面的专家。
ratios = sorted(self.resDict.keys(), reverse=False)
nativeIndex = ratios.index(self.nativeRatio)
res = ratios[nativeIndex + 1][0]
这是上一篇文章中提到的代码。再次感谢您的所有答案。
答案 0 :(得分:0)
好的,关于您发布的代码,这是我能够推断的内容。
width = float(res[0])
height = float(res[1])
ratio = round(width / height, 2)
self.resDict.setdefault(ratio, []).append(res)
# resDict is a dictionary of float -> list
然后你有:
ratios = sorted(self.resDict.keys(), reverse=False)
# ratios is a list of resDict keys (float)
nativeIndex = ratios.index(self.nativeRatio)
res = ratios[nativeIndex + 1][0]
# ratios[nativeIndex + 1] is a resDict key (float)
您尝试索引浮点值。我怀疑你正试图用该密钥索引字典。
selectedKey = ratios[nativeIndex + 1]
res = self.resDict[selectedKey][0]