Say I have a class in Python that has an eq method defined for comparing attributes for equality:
class Foo(object):
# init code...
def __eq__(self, other):
# usual eq code here....
How can I then compare two instances of Foo for reference equality (that is test if they are the same instance)? If I do:
f1 = Foo()
f2 = Foo()
print f1 == f2
I get True even though they are different objects.
question from:
https://stackoverflow.com/questions/7274097/testing-for-reference-equality-in-python 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…