0
有人能幫我理解這個bug嗎?在我的班 「怪物」 我有這樣的:Python:TypeError:unbound方法,必須用(class)instance調用
def mate_action(self):
if self.mate == 1:
for creature in creature_list:
if creature.mate == 1:
self.str_nb = (self.str + creature.str)/2
self.attr_nb = (self.attr + creature.attr)/2
self.cons_nb = (self.cons + creature.cons)/2
self.size_nb = (self.size + creature.size)/2
creature.mate = 0
creature_list.append(Creature)
for creature in creature_list:
if creature.alive == 0:
creature.alive = 1
creature.str = self.str_nb
creature.attr = self.attr_nb
creature.cons = self.cons_nb
creature.size = self.size_nb
creature.nb = 1
當我這樣做:
for creature in creature_list:
creature.mate_action()
我收到此錯誤:
TypeError: unbound method mate_action() must be called with Creature instance as first argument (got nothing instead)
謝謝你的任何及所有的幫助!
您確定您的班級被命名爲「生物」而不是「生物」嗎?請注意領先的大寫字母。 – jedwards
creature_list的內容是什麼? –
@jedwards它在裏面,正確縮進 –