我在模块中有一个如下声明的python类
class Position:
def __init__(self, x, y):
self.x = int(x)
self.y = int(y)
def __str__(self):
return self.toString()
def toString(self): #deprecated
return "{x:"+str(self.x)+" y:"+str(self.y)+"}"
现在,稍后在主程序中,我进行如下比较:
can_pos = somestreet.endOfStreet(curPos).getPos() #returns a Position object
if(can_pos == atPos): # this returns False
#blafoo
#if(can_pos.x == atPos.x and can_pos.y == atPos.y): #this returns True (and is expected)
我不明白不同行为的原因可能是什么......
如果有人能给我一个提示,那就太好了:)
提前致谢