Re: Newbie Question - Overloading ==

2008-04-04 Thread Lie
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 > >

Re: Newbie Question - Overloading ==

2008-04-01 Thread Bruno Desthuilliers
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: >>>

Re: Newbie Question - Overloading ==

2008-04-01 Thread Duncan Booth
"[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): >>

Re: Newbie Question - Overloading ==

2008-03-31 Thread xkenneth
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

Re: Newbie Question - Overloading ==

2008-03-31 Thread Amit Gupta
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

Re: Newbie Question - Overloading ==

2008-03-31 Thread [EMAIL PROTECTED]
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

Re: Newbie Question - Overloading ==

2008-03-31 Thread Carl Banks
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

Re: Newbie Question - Overloading ==

2008-03-31 Thread Duncan Booth
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

Re: Newbie Question - Overloading ==

2008-03-31 Thread xkenneth
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

Re: Newbie Question - Overloading ==

2008-03-31 Thread Jean-Paul Calderone
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

Re: Newbie Question - Overloading ==

2008-03-31 Thread Amit Gupta
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

Newbie Question - Overloading ==

2008-03-31 Thread xkenneth
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