randomState = collections.namedtuple('randomState', ['player', 'score'])
假设我有一个包含 player/score 的 namedtuple,如果我要替换这些函数中的任何一个,我会这样做:
def random(state):
return state._replace(score='123')
如何创建一个具有基本上类似于命名元组的函数的类,并且能够手动替换任一玩家/分数?
class Random:
def abc(self, score):
if self.score == '123':
###had it were a namedtuple, I would use the replace function here, but classes don't allow me to do that so how would I replace 'score' manually?
我不确定我在这里是否有意义,但如果有人理解我的问题,我将非常感谢您的反馈。谢谢