On Apr 1, 2:22 pm, Duncan Booth <[EMAIL PROTECTED]> wrote:
> "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> >> Surely an A isn't equal to every other object which just happens to
> >> have the same attributes 'a' and 'b'?
>
> > And why not ?-)
>
> >> I would have thoughts the tests want to be
> >
Duncan Booth a écrit :
> "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
>
>>> Surely an A isn't equal to every other object which just happens to
>>> have the same attributes 'a' and 'b'?
>> And why not ?-)
>>
>>> I would have thoughts the tests want to be
>>> something like:
>>>
>>> class A:
>>>
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
>> Surely an A isn't equal to every other object which just happens to
>> have the same attributes 'a' and 'b'?
>
> And why not ?-)
>
>> I would have thoughts the tests want to be
>> something like:
>>
>> class A:
>> def __eq__(self,other):
>>
On Mar 31, 3:42 pm, Amit Gupta <[EMAIL PROTECTED]> wrote:
> On Mar 31, 11:00 am, xkenneth <[EMAIL PROTECTED]> wrote:
>
> > Yeah, this is what I'm talking about:
>
> > > def __eq__(self, other) :
> > > try :
> > > return <>
> > > except AttributeError:
> > > return False
>
> > That see
On Mar 31, 11:00 am, xkenneth <[EMAIL PROTECTED]> wrote:
> Yeah, this is what I'm talking about:
>
> > def __eq__(self, other) :
> > try :
> > return <>
> > except AttributeError:
> > return False
>
> That seems a bit nasty to me.
One thing about python (IMO); you can't just say this
On 31 mar, 20:09, Duncan Booth <[EMAIL PROTECTED]> wrote:
> xkenneth <[EMAIL PROTECTED]> wrote:
> > Now obviously, if I test an instance of either class equal to each
> > other, an attribute error will be thrown, how do I handle this? I
> > could rewrite every __eq__ function and catch attribute er
On Mar 31, 1:23 pm, xkenneth <[EMAIL PROTECTED]> wrote:
> So i generally write quite a few classes, and in most I need to
> overload the == operator.
>
> If i have two classes, like below:
>
> Class A:
> attribute a
> attribute b
>
> Class B:
> attribute a
> attribute c
>
> So if I've overloaded th
xkenneth <[EMAIL PROTECTED]> wrote:
> Now obviously, if I test an instance of either class equal to each
> 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
Yeah, this is what I'm talking about:
> def __eq__(self, other) :
> try :
> return <>
> except AttributeError:
> return False
That seems a bit nasty to me.
--
http://mail.python.org/mailman/listinfo/python-list
On Mon, 31 Mar 2008 10:23:24 -0700 (PDT), xkenneth <[EMAIL PROTECTED]> wrote:
>So i generally write quite a few classes, and in most I need to
>overload the == operator.
>
>If i have two classes, like below:
>
>Class A:
>attribute a
>attribute b
>
>Class B:
>attribute a
>attribute c
>
>So if I've o
On Mar 31, 10:23 am, xkenneth <[EMAIL PROTECTED]> 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 Mille
So i generally write quite a few classes, and in most I need to
overload the == operator.
If i have two classes, like below:
Class A:
attribute a
attribute b
Class B:
attribute a
attribute c
So if I've overloaded their respective __eq__ functions, and I want to
test whether or not the individua
12 matches
Mail list logo