我正在livewires中编写一个chess程序,当我尝试运行一个函数时,一个属性(应该包含一个对象)突然被设置为None。下面是代码中导致问题的方法的一个片段:
from livewires import games
....
def toggle(self):
piece = self.hold
...
elif piece.type == "K":
if "CASTLE_R" in piece.moveset:
#piece is still an object, i used print
piece.hasmoved = True
#piece still an object
self.boxremove()
...
def boxremove(self):
piece = self.hold
#suddenly piece is not an object
print self.hold
for item in piece.poss: #here it says an error that piece is NoneType
item.destroy()
...
我很困惑为什么它突然变成了一个非类型,因为我没有做任何事情来编辑这些部分之间的它。你知道吗
完整的代码可以在这里找到:https://www.dropbox.com/s/rzhq9fek7qtzims/chess.py?dl=0 在210线附近。你知道吗
好吧,你在你的类
__init__
中设置了self.hold = None
。这意味着有一个地方/情况,它从来没有被设置,并保持None
,直到您的错误点。为了找到问题,您必须在比所显示的代码更大的代码段中进行调试。你知道吗相关问题 更多 >
编程相关推荐