Re: Is there a way to implement the ** operator on a custom object

2024-02-09 Thread Cameron Simpson via Python-list
On 09Feb2024 18:56, Left Right wrote: But, more to the point: extending collections.abc.Mapping may or may not be possible in OP's case. We don't yet know if that's what the OP had in mind yet, anyway. Also, if you are doing this through inheritance, this seems really convoluted: why not jus

Re: Is there a way to implement the ** operator on a custom object

2024-02-09 Thread Left Right via Python-list
> Looks like it can simply be done in Python, no tp_as_mapping needed. It's not that it isn't needed. You've just shown a way to add it using Python code. But, more to the point: extending collections.abc.Mapping may or may not be possible in OP's case. Also, if you are doing this through inheri

Re: Is there a way to implement the ** operator on a custom object

2024-02-09 Thread Roel Schroeven via Python-list
Left Right via Python-list schreef op 9/02/2024 om 17:09: In order for the "splat" operator to work, the type of the object must populate slot `tp_as_mapping` with a struct of this type: https://docs.python.org/3/c-api/typeobj.html#c.PyMappingMethods and have some non-null implementations of the

Re: Is there a way to implement the ** operator on a custom object

2024-02-09 Thread Left Right via Python-list
In order for the "splat" operator to work, the type of the object must populate slot `tp_as_mapping` with a struct of this type: https://docs.python.org/3/c-api/typeobj.html#c.PyMappingMethods and have some non-null implementations of the methods this struct is supposed to contain. I can do this i

Re: Is there a way to implement the ** operator on a custom object

2024-02-09 Thread Alan Bawden via Python-list
Chris Angelico writes: > On 08Feb2024 12:21, tony.fl...@btinternet.com wrote: > >I know that mappings by default support the ** operator, to unpack the > >mapping into key word arguments. > > > >Has it been considered implementing a dunder method for t

Re: Is there a way to implement the ** operator on a custom object

2024-02-08 Thread Chris Angelico via Python-list
On Fri, 9 Feb 2024 at 17:03, Cameron Simpson via Python-list wrote: > > On 08Feb2024 12:21, tony.fl...@btinternet.com > wrote: > >I know that mappings by default support the ** operator, to unpack the > >mapping into key word arguments. > > > >Has it been consid

Re: Is there a way to implement the ** operator on a custom object

2024-02-08 Thread Cameron Simpson via Python-list
On 08Feb2024 12:21, tony.fl...@btinternet.com wrote: I know that mappings by default support the ** operator, to unpack the mapping into key word arguments. Has it been considered implementing a dunder method for the ** operator so you could unpack an object into a key word argument, and

Is there a way to implement the ** operator on a custom object

2024-02-08 Thread Tony Flury via Python-list
I know that mappings by default support the ** operator, to unpack the mapping into key word arguments. Has it been considered implementing a dunder method for the ** operator so you could unpack an object into a key word argument, and the developer could choose which keywords would be

Re: semantics of the |= operator

2008-08-24 Thread akva
thanks everybody. -- http://mail.python.org/mailman/listinfo/python-list

Re: semantics of the |= operator

2008-08-22 Thread Peter Pearson
On Fri, 22 Aug 2008 00:35:31 -0700 (PDT), akva <[EMAIL PROTECTED]> wrote: > > well, frankly I expected a |= b to mean exactly the same as a = a | b > regardless of the object type. So did I. I'm glad your post called this to my attention; I recently told my kid exactly that wrong thing. -- To

Re: semantics of the |= operator

2008-08-22 Thread Fredrik Lundh
akva wrote: could you please refer me a link where this is specified? I couldn't find it in python documentation http://docs.python.org/ref/augassign.html "An augmented assignment expression like x += 1 can be rewritten as x = x + 1 to achieve a similar, but not exactly equal effect. In the

Re: semantics of the |= operator

2008-08-22 Thread akva
thanks all, >Yes. That's the exact purpose of the in-place operators when they deal with >mutable objects. What else did you expect? well, frankly I expected a |= b to mean exactly the same as a = a | b regardless of the object type. > The manual explicitly specifies that mutable objects may imp

Re: semantics of the |= operator

2008-08-21 Thread Terry Reedy
akva wrote: Hi All, what's the exact semantics of the |= operator in python? It seems that a |= d is not always equivalent to a = a | d The manual explicitly specifies that mutable objects may implement the operation part of operation-assignments by updating in place -- so that

Re: semantics of the |= operator

2008-08-21 Thread Diez B. Roggisch
akva wrote: > Hi All, > > what's the exact semantics of the |= operator in python? > It seems that a |= d is not always equivalent to a = a | d > > For example let's consider the following code: > > def foo(s): >s = s | set([10]) > > def ba

semantics of the |= operator

2008-08-21 Thread akva
Hi All, what's the exact semantics of the |= operator in python? It seems that a |= d is not always equivalent to a = a | d For example let's consider the following code: def foo(s): s = s | set([10]) def bar(s): s |= set([10]) s = set([1,2]) foo(s) print s # prints set([1,

Re: The ** operator ambiguous?

2007-07-17 Thread Duncan Booth
Paul Boddie <[EMAIL PROTECTED]> wrote: > However, this ambiguous usage of * and ** is one thing I don't recall > appearing on any of the "Python warts" lists It is true that the same punctuation character is used in more than one context, but that is also true for many other punctuation character

Re: The ** operator ambiguous?

2007-07-16 Thread Paul Boddie
Robert Dailey wrote: > I noticed that the ** operator is used as the power operator, however > I've seen it used when passing variables into a function. Others have already pointed out the relevant documentation. However, this ambiguous usage of * and ** is one thing I don't rec

Re: The ** operator ambiguous?

2007-07-16 Thread Klaas
On Jul 16, 10:40 am, Robert Dailey <[EMAIL PROTECTED]> wrote: > I noticed that the ** operator is used as the power operator, however > I've seen it used when passing variables into a function. For example, > I was researching a way to combine dictionaries. I found that if

Re: The ** operator ambiguous?

2007-07-16 Thread Gabriel Genellina
En Mon, 16 Jul 2007 14:40:14 -0300, Robert Dailey <[EMAIL PROTECTED]> escribió: > I noticed that the ** operator is used as the power operator, however > I've seen it used when passing variables into a function. For example, > I was researching a way to combine dictionaries.

Re: The ** operator ambiguous?

2007-07-16 Thread Duncan Booth
Robert Dailey <[EMAIL PROTECTED]> wrote: > However, I have no idea what the > ** operator is here. I know that when you specify ** as a parameter in > a function definition, it represents a dictionary of parameters passed > in. However, in this example it is NOT being

Re: The ** operator ambiguous?

2007-07-16 Thread Diez B. Roggisch
Robert Dailey schrieb: > I noticed that the ** operator is used as the power operator, however > I've seen it used when passing variables into a function. For example, > I was researching a way to combine dictionaries. I found that if you > do this: > > a = {"t1&qu

The ** operator ambiguous?

2007-07-16 Thread Robert Dailey
I noticed that the ** operator is used as the power operator, however I've seen it used when passing variables into a function. For example, I was researching a way to combine dictionaries. I found that if you do this: a = {"t1":"a", "t2":"b"} b = {&qu

Re: The ^ operator

2005-09-26 Thread Steve Holden
Tuvas wrote: > What exactly does the ^ operator do? I've seen, for example, that > 3^4=7, 3^5=8. but 3^3=0. Is it just adding them together if they are > not equal, and if they are equal, outputs 0, or what? Thanks! > ^ is the "bit XOR" operation. It treats its left an

Re: The ^ operator

2005-09-26 Thread Tuvas
Thanks alot! That sure makes lots of sense! -- http://mail.python.org/mailman/listinfo/python-list

Re: The ^ operator

2005-09-26 Thread Peter Hansen
Tuvas wrote: > What exactly does the ^ operator do? I've seen, for example, that > 3^4=7, 3^5=8. but 3^3=0. Is it just adding them together if they are > not equal, and if they are equal, outputs 0, or what? Thanks! It performs an "exclusive-OR" (XOR) operation on the bi

The ^ operator

2005-09-26 Thread Tuvas
What exactly does the ^ operator do? I've seen, for example, that 3^4=7, 3^5=8. but 3^3=0. Is it just adding them together if they are not equal, and if they are equal, outputs 0, or what? Thanks! -- http://mail.python.org/mailman/listinfo/python-list

Re: Annoying behaviour of the != operator

2005-06-23 Thread Steven D'Aprano
Max wrote: > Jordan Rastrick wrote: >> Well, never, ever use equality or inequality operations with floating >> point numbers anyway, in any language, as they are notoriously >> unreliable due to the inherent inaccuracy of floating point. Thats >> another pitfall, I'll grant, but its a pretty well

Re: Annoying behaviour of the != operator

2005-06-23 Thread Max
Jordan Rastrick wrote: > I don't want to order the objects. I just want to be able to say if one > is equal to the other. > > Here's the justification given: > > The == and != operators are not assumed to be each other's > complement (e.g. IEEE 754 floating point numbers do not satisf

Re: Annoying behaviour of the != operator

2005-06-13 Thread Rocco Moretti
Before I answer, let me clarify my position. I am NOT advocating any change for the 2.x series. I'm not even forwarding any particular proposal for 3.0/3000. My key (and close to sole) point is that behavior of > & < is conceptually distinct from ordering in a sorted list, even though the beha

Re: string formatting using the % operator

2005-06-13 Thread Peter Hansen
Dan Sommers wrote: > Let the DB-API do more work for you: > > cursor = connection.cursor( ) > sql = """SELECT column2, columns3 FROM table WHERE name LIKE %s""" > values = ('%%%s%%' % searchterm,) # note that this is a tuple It l

Re: string formatting using the % operator

2005-06-13 Thread William Gill
Dan Sommers wrote: > On Mon, 13 Jun 2005 15:12:54 GMT, > William Gill <[EMAIL PROTECTED]> wrote: > > >>I am using the % operator to create queries for a db app. It works fine >>when exact strings, or numbers are used, but some queries need partial >>matching

Re: string formatting using the % operator

2005-06-13 Thread Dan Sommers
On Mon, 13 Jun 2005 15:12:54 GMT, William Gill <[EMAIL PROTECTED]> wrote: > I am using the % operator to create queries for a db app. It works fine > when exact strings, or numbers are used, but some queries need partial > matching that use the '%' as a wildcards. So

Re: string formatting using the % operator

2005-06-13 Thread harold fellermann
> to return 'WHERE name LIKE %smith%'I have tried using escapes, > character codes for the % sign, and lots of other gyrations with no > success. The only thing that works is if I modify searchterm first: > >searchterm = 'smith' >searchterm ='%'+'smith'+'%' >sql += 'WHE

Re: string formatting using the % operator

2005-06-13 Thread fargo
William Gill wrote: > I am using the % operator to create queries for a db app. It works fine > when exact strings, or numbers are used, but some queries need partial > matching that use the '%' as a wildcards. So for example the resultant > string should be 'WHERE

string formatting using the % operator

2005-06-13 Thread William Gill
I am using the % operator to create queries for a db app. It works fine when exact strings, or numbers are used, but some queries need partial matching that use the '%' as a wildcards. So for example the resultant string should be 'WHERE name LIKE %smith%' (would match

Re: Annoying behaviour of the != operator

2005-06-12 Thread pmaupin
If a behavior change is possible at all, I think a more reasonable behavior would be: if any rich comparison methods are defined, always use rich comparisons (and throw an exception if the required rich comparison method is not available). This would at least have the benefit of letting users kno

Re: Annoying behaviour of the != operator

2005-06-10 Thread David M. Cooke
Robert Kern <[EMAIL PROTECTED]> writes: > greg wrote: >> David M. Cooke wrote: >> To solve that, I would suggest a fourth category of "arbitrary ordering", but that's probably Py3k material. >>> >>>We've got that: use hash(). >>>[1+2j, 3+4j].sort(key=hash) >> What about objects that are no

Re: Annoying behaviour of the != operator

2005-06-10 Thread Dan Sommers
On Fri, 10 Jun 2005 09:50:56 -0500, Rocco Moretti <[EMAIL PROTECTED]> wrote: > Dan Sommers wrote: >> On Thu, 09 Jun 2005 15:50:42 +1200, >> Greg Ewing <[EMAIL PROTECTED]> wrote: >> >>> Rocco Moretti wrote: >>> The main problem is that Python is trying to stick at least three different

Re: Annoying behaviour of the != operator

2005-06-10 Thread Rocco Moretti
George Sakkis wrote: > "Rocco Moretti" wrote: > > >>One way to handle that is to refuse to sort anything that doesn't have a >>"natural" order. But as I understand it, Guido decided that being able >>to sort arbitrary lists is a feature, not a bug. > > > He has changed his mind since then > (ht

Re: Annoying behaviour of the != operator

2005-06-10 Thread Terry Reedy
"Rocco Moretti" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > The "wackyness" I refered to wasn't that a list of complex numbers isn't > sortable, but the inconsistent behaviour of list sorting. As you > mentioned, an arbitraty collection of objects in a list is sortable, but > as

Re: Annoying behaviour of the != operator

2005-06-10 Thread Jp Calderone
On 10 Jun 2005 09:05:53 -0700, Dan Bishop <[EMAIL PROTECTED]> wrote: >Steven D'Aprano wrote: >... >> If you were to ask, "which is bigger, 1+2j or 3+4j?" then you >> are asking a question about mathematical size. There is no unique answer >> (although taking the absolute value must surely come clos

Re: Annoying behaviour of the != operator

2005-06-10 Thread Dan Bishop
Steven D'Aprano wrote: ... > If you were to ask, "which is bigger, 1+2j or 3+4j?" then you > are asking a question about mathematical size. There is no unique answer > (although taking the absolute value must surely come close) and the > expression 1+2j > 3+4j is undefined. > > But if you ask "whic

Re: Annoying behaviour of the != operator

2005-06-10 Thread George Sakkis
"Rocco Moretti" wrote: > One way to handle that is to refuse to sort anything that doesn't have a > "natural" order. But as I understand it, Guido decided that being able > to sort arbitrary lists is a feature, not a bug. He has changed his mind since then (http://mail.python.org/pipermail/python

Re: Annoying behaviour of the != operator

2005-06-10 Thread Rocco Moretti
Dan Sommers wrote: > On Thu, 09 Jun 2005 15:50:42 +1200, > Greg Ewing <[EMAIL PROTECTED]> wrote: > > >>Rocco Moretti wrote: >> >>>The main problem is that Python is trying to stick at least three >>>different concepts onto the same set of operators: equivalence (are >>>these two objects the same?

Re: Annoying behaviour of the != operator

2005-06-10 Thread Steven D'Aprano
On Thu, 09 Jun 2005 08:10:09 -0400, Dan Sommers wrote: >>> The main problem is that Python is trying to stick at least three >>> different concepts onto the same set of operators: equivalence (are >>> these two objects the same?), ordering (in a sorted list, which comes >>> first?), and mathematic

Re: Annoying behaviour of the != operator

2005-06-10 Thread Robert Kern
greg wrote: > David M. Cooke wrote: > >>>To solve that, I would suggest a fourth category of "arbitrary >>>ordering", but that's probably Py3k material. >> >>We've got that: use hash(). >>[1+2j, 3+4j].sort(key=hash) > > What about objects that are not hashable? > > The purpose of arbitrary order

Re: Annoying behaviour of the != operator

2005-06-10 Thread greg
David M. Cooke wrote: >>To solve that, I would suggest a fourth category of "arbitrary >>ordering", but that's probably Py3k material. > > We've got that: use hash(). > [1+2j, 3+4j].sort(key=hash) What about objects that are not hashable? The purpose of arbitrary ordering would be to provide an

Re: Annoying behaviour of the != operator

2005-06-09 Thread David M. Cooke
Greg Ewing <[EMAIL PROTECTED]> writes: > Rocco Moretti wrote: > > > This gives the wacky world where >> "[(1,2), (3,4)].sort()" works, whereas "[1+2j, 3+4j].sort()" doesn't. > > To solve that, I would suggest a fourth category of "arbitrary > ordering", but that's probably Py3k material. We've g

Re: Annoying behaviour of the != operator

2005-06-09 Thread Dan Sommers
On Thu, 09 Jun 2005 15:50:42 +1200, Greg Ewing <[EMAIL PROTECTED]> wrote: > Rocco Moretti wrote: >> The main problem is that Python is trying to stick at least three >> different concepts onto the same set of operators: equivalence (are >> these two objects the same?), ordering (in a sorted list,

Re: Annoying behaviour of the != operator

2005-06-09 Thread Antoon Pardon
already smart. It deduces what you want with the += operator even if you haven't defined an __iadd__ method. If python can be smart with that, I don't see python being smart with !=. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list

Re: Annoying behaviour of the != operator

2005-06-08 Thread Greg Ewing
Rocco Moretti wrote: > The main problem is that Python is trying to stick at least three > different concepts onto the same set of operators: equivalence (are > these two objects the same?), ordering (in a sorted list, which comes > first?), and mathematical "size". A possible compromise would

Re: Annoying behaviour of the != operator

2005-06-08 Thread Greg Ewing
Jordan Rastrick wrote: > Where are the 'number of situations' where __ne__ cannot be derived > from __eq__? Is it just the floating point one? I must admit, I've > missed any others. The floating point one is just an example, it's not meant to be the entire justification. Some others: * Numeric

Re: Annoying behaviour of the != operator

2005-06-08 Thread Greg Ewing
Jordan Rastrick wrote: > But I explicitly provided a method to test equality. Actually, no, you didn't. You provided a method to define the meaning of the operator spelled '==' when applied to your object. That's the level of abstraction at which Python's __xxx__ m

Re: Annoying behaviour of the != operator

2005-06-08 Thread Steven D'Aprano
ot is" instead of "not equal"? That seems like an especially perverse choice given that the operator is actually called "not equal". > So, s != t is True because the ids of the two objects are different. > The same applies to, for example s > t and s < t. Do you

Re: Annoying behaviour of the != operator

2005-06-08 Thread Peter Hansen
Robert Kern wrote: > The problem arises that, in the presence of rich comparisons, (a == b) > is not always a boolean value, while (a is b) is always a boolean value. But that still doesn't mean that in a case where a == b (via __eq__) returns a non-boolean, __ne__ would not be defined as well.

Re: Annoying behaviour of the != operator

2005-06-08 Thread Peter Hansen
Christopher Subich wrote: > Perhaps the language should offer > the sensible default of (!=) == (not ==) if one of them but not the > other is overriden, but still allow overriding of both. I believe that's exactly what Jordan is promoting and, having been bitten in exactly the same way I would

Re: Annoying behaviour of the != operator

2005-06-08 Thread Dan Bishop
Mahesh wrote: > I understand that what makes perfect sense to me might not make perfect > sense to you but it seems a sane default. When you compare two objects, > what is that comparision based on? In the explicit is better than > implicit world, Python can only assume that you *really* do want to

Re: Annoying behaviour of the != operator

2005-06-08 Thread John Roth
"Jordan Rastrick" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Well, I'll admit I haven't ever used the Numeric module, but since > PEP207 was submitted and accepted, with Numeric as apparently one of > its main motivations, I'm going to assume that the pros and cons for > having

Re: Annoying behaviour of the != operator

2005-06-08 Thread Mahesh
I understand that what makes perfect sense to me might not make perfect sense to you but it seems a sane default. When you compare two objects, what is that comparision based on? In the explicit is better than implicit world, Python can only assume that you *really* do want to compare objects unles

Re: Annoying behaviour of the != operator

2005-06-08 Thread Robert Kern
Jordan Rastrick wrote: > Mahesh raised the argument some posts back that Python should not 'just > guess' what you want. But the problem is, it *already does* - it > guesses you want object identity comparison if you haven't written > __ne__. But if __ne__ is not provided, than the negation of >

Re: Annoying behaviour of the != operator

2005-06-08 Thread Jordan Rastrick
I'm a Maths and Philosophy undergraduate first and foremost, with Computer Science as a tacked on third; I've studied a fair bit of logic both informally and formally, and am familiar with things such as the non-nessecity of the law of the excluded middle in an arbitrary propositional calculus farm

Re: Annoying behaviour of the != operator

2005-06-08 Thread Christopher Subich
Peter Hansen wrote: > I can see only one comment that seems to describe that situation, where it refers to "IEEE 754 floating point numbers do not satisfy [== being the complement of !=]". > > (Though that may be justification enough for the feature...) To my naive eye, that possibility see

Re: Annoying behaviour of the != operator

2005-06-08 Thread Rocco Moretti
Matt Warden wrote: > Jordan, > > On 8 Jun 2005 11:44:43 -0700, Jordan Rastrick > <[EMAIL PROTECTED]> wrote: > >>But I explicitly provided a method to test equality. And look at the >>plain english meaning of the term "Not equals" I think its pretty >>reasonable > > > Indeed. Furthermore, it see

Re: Annoying behaviour of the != operator

2005-06-08 Thread Kay Schluehr
Jordan Rastrick wrote: > Just because a behaviour is documented, doesn't mean its not counter > intutitive, potentially confusing, and unnessecary. > > I have spent a fair amount of time reading the Python docs. I have not > yet memorised them. I may have read this particular section of the > ref

Re: Annoying behaviour of the != operator

2005-06-08 Thread Jordan Rastrick
Well, I'll admit I haven't ever used the Numeric module, but since PEP207 was submitted and accepted, with Numeric as apparently one of its main motivations, I'm going to assume that the pros and cons for having == and ilk return things other than True or False have already been discussed at length

Re: Annoying behaviour of the != operator

2005-06-08 Thread George Sakkis
"Jordan Rastrick" wrote: > I'd suggest the only nessecary change is, if objects a,b both define > __eq__ and not __ne__, then a != b should return not (a == b) > > If a class defines __ne__ but not __eq__, well that seems pretty > perverse to me. I don't especially care one way or another how that

Re: Annoying behaviour of the != operator

2005-06-08 Thread Robert Kern
Jordan Rastrick wrote: > Are there any other reasonable examples people can give where it makes > sense for != and == not to be each other's complement? __eq__ and __ne__ implement *rich* comparisons. They don't have to return only True or False. In [1]:import Numeric In [2]:a = Numeric.array(

Re: Annoying behaviour of the != operator

2005-06-08 Thread Matt Warden
Jordan, On 8 Jun 2005 11:44:43 -0700, Jordan Rastrick <[EMAIL PROTECTED]> wrote: > But I explicitly provided a method to test equality. And look at the > plain english meaning of the term "Not equals" I think its pretty > reasonable Indeed. Furthermore, it seems quite silly that these would be di

Re: Annoying behaviour of the != operator

2005-06-08 Thread Jordan Rastrick
I'd suggest the only nessecary change is, if objects a,b both define __eq__ and not __ne__, then a != b should return not (a == b) If a class defines __ne__ but not __eq__, well that seems pretty perverse to me. I don't especially care one way or another how thats resolved to be honest. The order

Re: Annoying behaviour of the != operator

2005-06-08 Thread John Roth
"Jordan Rastrick" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Well, I don't really want the objects to be comparable. In fact, to > quote that PEP you linked: > > An additional motivation is that frequently, types don't have a > natural ordering, but still need to be co

Re: Annoying behaviour of the != operator

2005-06-08 Thread Rocco Moretti
Jordan Rastrick wrote: > Unless someone can explain some sort of problem that arises from having > != take advantage of a __eq__ method where present, I'd suggest that it > should do so in Python 2.5. If you're serious about this proposal, please formalize it in a PEP. Things to specify: How ex

Re: Annoying behaviour of the != operator

2005-06-08 Thread Jordan Rastrick
Just because a behaviour is documented, doesn't mean its not counter intutitive, potentially confusing, and unnessecary. I have spent a fair amount of time reading the Python docs. I have not yet memorised them. I may have read this particular section of the reference manual, or I may have not, I

Re: Annoying behaviour of the != operator

2005-06-08 Thread Peter Hansen
Fredrik Lundh wrote: > for a number of situations where __ne__ cannot be derived from __eq__, > see: > > http://www.python.org/peps/pep-0207.html That "number" being "one"? I can see only one comment that seems to describe that situation, where it refers to "IEEE 754 floating point numbers

Re: Annoying behaviour of the != operator

2005-06-08 Thread Jordan Rastrick
Well, I don't really want the objects to be comparable. In fact, to quote that PEP you linked: An additional motivation is that frequently, types don't have a natural ordering, but still need to be compared for equality. Currently such a type *must* implement comparison and thus

Re: Annoying behaviour of the != operator

2005-06-08 Thread Dan Bishop
Mahesh wrote: > No, why should Python assume that if you use != without supplying a > __ne__ that this is what you want? Because every single time I've used __ne__, that *is* what I want. > Without direction it will compare > the two objects which is the default behavior. It's also the default b

Re: Annoying behaviour of the != operator

2005-06-08 Thread Mahesh
No, why should Python assume that if you use != without supplying a __ne__ that this is what you want? Without direction it will compare the two objects which is the default behavior. So, s != t is True because the ids of the two objects are different. The same applies to, for example s > t and s

Re: Annoying behaviour of the != operator

2005-06-08 Thread Fredrik Lundh
Jordan Rastrick wrote: > I just spent a long, long time tracking down a bug in a program that > results from this behaviour. > > Surely the != operator should, if no __ne__ method is present for > either object, check to see if an __eq__ method is defined, and if so, > r

Re: Annoying behaviour of the != operator

2005-06-08 Thread Dave Benjamin
Jordan Rastrick wrote: > Surely the != operator should, if no __ne__ method is present for > either object, check to see if an __eq__ method is defined, and if so, > return its negation? > > Actually, that brings me to a wider question - why does __ne__ exist at > all? Sur

Annoying behaviour of the != operator

2005-06-08 Thread Jordan Rastrick
me tracking down a bug in a program that results from this behaviour. Surely the != operator should, if no __ne__ method is present for either object, check to see if an __eq__ method is defined, and if so, return its negation? Actually, that brings me to a wider question - why does __ne__ exist