Possible Duplicate:
python: class override “is” behavior
I am trying to override the is
operator, so that I could do something like
if tom is writer:
print 'tom is writing'
elif tom is programmer:
print 'tom is programming'
Is this possible in python?
As far as I know, you can't override 'is' because it tests whether two objects are the same object by comparing their memory addresses (i.e. pointer comparison). You probably want to override '==' by implementing tom's __eq__
method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With