Python 类型错误:'&燃气轮机';在';内置函数或方法';和';dict';

Python 类型错误:'&燃气轮机';在';内置函数或方法';和';dict';,python,python-3.x,dictionary,Python,Python 3.x,Dictionary,我得到了以下错误类型错误:“>”在我尝试执行此行时,在“内置函数”或“方法”的实例之间不受支持 最佳玩家=最大值(self.players\u分数,self.players\u分数,get) 这是我的密码: class-Yatzy: 定义初始化(自我、人类、机器人):(…) @财产 def玩家_分数(自我): 分数={} 对于范围内的i(len(self.humans)): 分数[self.humans[i].name]=self.humans[i]。总分 对于范围内的i(len(self.b

我得到了以下错误类型错误:“>”在我尝试执行此行时,在“内置函数”或“方法”的实例之间不受支持

最佳玩家=最大值(self.players\u分数,self.players\u分数,get)

这是我的密码:

class-Yatzy:
定义初始化(自我、人类、机器人):(…)
@财产
def玩家_分数(自我):
分数={}
对于范围内的i(len(self.humans)):
分数[self.humans[i].name]=self.humans[i]。总分
对于范围内的i(len(self.bots)):
分数[self.bots[i].name]=self.bots[i]。总分
打印(类型(self.bots[0]。名称),类型(self.bots[0]。总分))
返回分数
def game_循环(自):
打印(“欢迎来到Yatzy游戏!”)
圆形计数器=1
轮_计数器回溯时(最近一次呼叫最后一次):
文件
>“C:/Users/Artur/Desktop/Python/yatzy/yatzy.py”,第140行,在
>game.game_loop()
文件“C:/Users/Artur/Desktop/Python/yatzy/yatzy.py”,第135行,在游戏循环中
>最佳玩家=最大值(self.players\u分数,self.players\u分数,get)
TypeError:“”的实例之间不支持“>”
>“内置函数或方法”和“dict”

max的参数需要是数字,或者,非常具体地说,正如您收到的错误消息所指出的,需要支持彼此之间的大于比较(通过实现Python的
\ugt\uu
方法)。如果传入不满足此条件的对象,则会出现错误

在本例中,您似乎忘记将第二个参数标识为关键字参数

best\u player=max(self.players\u scores,key=self.players\u scores.get)

max
也有点奇怪,因为它接受一个列表(显然是您想要的)或一系列非关键字参数作为列表进行比较。

max的参数需要是数字,或者,非常具体地说,如您收到的错误消息所示,需要相互支持大于比较(通过实现Python的
\uu gt\uu
方法)。如果传入不满足此条件的对象,则会出现错误

在本例中,您似乎忘记将第二个参数标识为关键字参数

best\u player=max(self.players\u scores,key=self.players\u scores.get)

max
也有点奇怪,因为它接受一个列表(显然是您想要的)或一系列非关键字参数作为列表进行比较。

如果方法不是
属性,您必须调用它们。呃,我忘了写key=self.players\u scores。get
player\u scores
是一个
@属性
,因此,你不必调用
get
,因为它没有这样的方法…@ArturOwczarek如果你忘记在你的问题中添加一些东西-编辑问题,不要在评论中添加它。我的意思是在
best\u player=max(self.players\u scores,self.players\u scores.get)行中
应该是
best\u player=max(self.players\u scores,key=self.players\u scores.get)
。现在它可以工作了。如果方法不是
属性,你就必须调用它们。呃,我忘了写key=self.players\u scores。get
player\u scores
@属性,因此你不必在它上面调用
get
,因为上面没有这样的方法…@ArturOwczarek如果你忘了在你的任务中添加一些东西的话离子-编辑问题,不要在评论中添加它。我的意思是在
best\u player=max(self.players\u scores,self.players\u scores.get)
应该是
best\u player=max(self.players\u scores,key=self.players\u scores.get)
,现在可以了。
Key type: <class 'str'> Value type: <class 'int'>
Final score: {'Bot1': 112, 'Bot2': 110, 'Bot3': 81, 'Bot4': 79}
Key type: <class 'str'> Value type: <class 'int'>
Key type: <class 'str'> Value type: <class 'int'>
Key type: <class 'str'> Value type: <class 'int'>
<class 'dict'> <class 'dict_keys'> <class 'dict_values'>
Key type: <class 'str'> Value type: <class 'int'>
Key type: <class 'str'> Value type: <class 'int'>

    > Traceback (most recent call last):  
 File
    > "C:/Users/Artur/Desktop/Python/yatzy/yatzy.py", line 140, in <module>
    >     game.game_loop()  
 File "C:/Users/Artur/Desktop/Python/yatzy/yatzy.py", line 135, in game_loop
    >     best_player = max(self.players_scores, self.players_scores.get)
 TypeError: '>' not supported between instances of
    > 'builtin_function_or_method' and 'dict'