Re: Newbie Question - Overloading ==
- From: Duncan Booth <duncan.booth@xxxxxxxxxxxxxxx>
- Date: 31 Mar 2008 18:09:42 GMT
xkenneth <xkenneth@xxxxxxxxx> wrote:
Now obviously, if I test an instance of either class equal to eachSurely an A isn't equal to every other object which just happens to have
other, an attribute error will be thrown, how do I handle this? I
could rewrite every __eq__ function and catch attribute errors, but
that's tedious, and seemingly unpythonic. Also, I don't want an
attribute error thrown whenever two classes are compared that don't
have the same attributes.
I have a sneaky feeling I'm doing something completely unpythonic
here.
the same attributes 'a' and 'b'? I would have thoughts the tests want to be
something like:
class A:
def __eq__(self,other):
return (isinstance(other, A) and
self.a == other.a and self.b == other.b)
(and similar for B) with either an isinstance or exact match required for
the type.
.
- Follow-Ups:
- Re: Newbie Question - Overloading ==
- From: bruno.desthuilliers@xxxxxxxxx
- Re: Newbie Question - Overloading ==
- References:
- Newbie Question - Overloading ==
- From: xkenneth
- Newbie Question - Overloading ==
- Prev by Date: Re: distutils as an application installer?
- Next by Date: Re: deleting a line from a file
- Previous by thread: Re: Newbie Question - Overloading ==
- Next by thread: Re: Newbie Question - Overloading ==
- Index(es):