Newbie Question - Overloading ==
Amit Gupta
emailamit at gmail.com
Mon Mar 31 13:26:51 EDT 2008
On Mar 31, 10:23 am, xkenneth <xkenn... at gmail.com> wrote:
>
> class A:
> def __eq__(self,other):
> return self.a == other.a and self.b == other.b
>
> class B:
> def __eq__(self,other):
> return self.a == other.a and self.c == other.c
>
> Thanks!
>
> Regards,
> Kenneth Miller
Can't say aboyt unpythonic: I am no expert at that: but to avoid
catching Attribute-Error everywhere, you can redefine __eq__ as
def __eq__(self, other) :
try :
return <>
except AttributeError:
return False
More information about the Python-list
mailing list