我可以传递我要查找的变量名作为参数吗?在下面的def中,stat参数用于更新函数中的 .stat 。 (见箭头)我一直收到错误:
print("game result :" +(self._playerHxDic[name][str(i)].stat))
属性错误:' GameHx'对象没有属性' stat'
def getStats(self,name,num_of_games,stat):
games = self._playerHxDic[name].keys()
gameNums = []
for i in games:
gameNums.append(int(i))
gameNums.sort()
if len(gameNums) > num_of_games:
gamelist = [int(x) for x in gameNums[-num_of_games:]]
points = 0
for i in gamelist:
points += statDicint(self._playerHxDic[name][i].stat)#<--
return points/num_of_games
else: return None