0
randomState = collections.namedtuple('randomState', ['player', 'score'])
比方說,我有一個包含播放器/得分namedtuple如果我是來取代任何的這些功能,我會做:Python類和替換函數?
def random(state):
return state._replace(score='123')
如何創建具有的功能,基本上類類似於一個namedtuple,並且能夠手動替換任一玩家/分數?
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?
我不知道如果我在這裏做的意義,但如果有人明白我的問題,我更感謝您的反饋。謝謝
OMG。非常感謝。我不敢相信我沒有想到這一點。 – Kara 2013-03-02 11:03:49