Python TypeError:“float”对象没有属性“\uuu getitem\uuu”错误
我试图玩这个游戏,我打开了所有的.Bat文件,虚拟的.Bat文件上写着Python TypeError:“float”对象没有属性“\uuu getitem\uuu”错误,python,Python,我试图玩这个游戏,我打开了所有的.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(re
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]
这是前一篇文章中提到的代码。再次感谢您的回答。好的,根据您发布的代码,我可以推断出以下内容
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]
请解释这是如何使用JavaScript的。事实上,这不是JavaScript,而是python为了找到错误的根源,您需要在ToonBase.py中发布代码。但似乎ratios或ratios[nativeIndex+1]属于浮点类型,因此没有实现用于[]运算符的_getitem_uuu方法。好的,当然,除了本机比率本身之外,我们没有任何与屏幕分辨率匹配的分辨率。让我们只使用第二大比率:ratios=sortedself.resDict.keys,reverse=False nativeIndex=ratios.indexself.nativeRatio res=ratios[nativeIndex+1][0]’这是Toonbase.py的代码,如果这有助于idkwidth=floatres[0]height=floatres[1],我也发现了这一点ratio=roundwidth/height,2 self.resDict.setdefaultratio,[].appendres我在ToonBase.py文件中找到了文本浮点。