Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #45234

Re: Differences of "!=" operator behavior in python3 and python2 [ bug? ]

From Alister <alister.ware@ntlworld.com>
Subject Re: Differences of "!=" operator behavior in python3 and python2 [ bug? ]
Newsgroups comp.lang.python
References <mailman.1603.1368401007.3114.python-list@python.org>
Message-ID <HP2kt.66723$Tl3.12499@fx29.fr7> (permalink)
Organization virginmedia.com
Date 2013-05-13 09:59 +0000

Show all headers | View raw


On Mon, 13 May 2013 05:23:16 +0600, Mr. Joe wrote:

> I seem to stumble upon a situation where "!=" operator misbehaves in
> python2.x. Not sure if it's my misunderstanding or a bug in python
> implementation. Here's a demo code to reproduce the behavior -
> """
> # -*- coding: utf-8 -*-
> from __future__ import unicode_literals, print_function
> 
> class DemoClass(object):
>     def __init__(self, val):
>         self.val = val
> 
>     def __eq__(self, other):
>         return self.val == other.val
> 
> x = DemoClass('a')
> y = DemoClass('a')
> 
> print("x == y: {0}".format(x == y))
> print("x != y: {0}".format(x != y))
> print("not x == y: {0}".format(not x == y))
> """
> 
> In python3, the output is as expected:
> """
> x == y: True x != y: False not x == y: False """
> 
> In python2.7.3, the output is:
> """
> x == y: True x != y: True not x == y: False """
> Which is not correct!!
> 
> Thanks in advance for clarifications.
> Regards,
> TB

this looks to me like an issue with operator precidence

you code is evaluating as (Not x) == y
rather than not (x == y)

why the difference between 2.7 & 3.X is beyond my knowledge of the 
language

The other explanations seem to detail things at low level but it is all 
Greek to me 


-- 
Nice guys finish last.
		-- Leo Durocher

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Differences of "!=" operator behavior in python3 and python2 [ bug? ] "Mr. Joe" <titanix88@gmail.com> - 2013-05-13 05:23 +0600
  Re: Differences of "!=" operator behavior in python3 and python2 [ bug? ] Alister <alister.ware@ntlworld.com> - 2013-05-13 09:59 +0000
    Re: Differences of "!=" operator behavior in python3 and python2 [ bug? ] Fábio Santos <fabiosantosart@gmail.com> - 2013-05-13 18:26 +0100
    Re: Differences of "!=" operator behavior in python3 and python2 [ bug? ] Ned Batchelder <ned@nedbatchelder.com> - 2013-05-13 14:08 -0400
    Re: Differences of "!=" operator behavior in python3 and python2 [ bug? ] Chris Angelico <rosuav@gmail.com> - 2013-05-14 04:15 +1000
    Re: Differences of "!=" operator behavior in python3 and python2 [ bug? ] Fábio Santos <fabiosantosart@gmail.com> - 2013-05-13 19:28 +0100
      Re: Differences of "!=" operator behavior in python3 and python2 [ bug? ] Alister <alister.ware@ntlworld.com> - 2013-05-13 21:17 +0000
        Re: Differences of "!=" operator behavior in python3 and python2 [ bug? ] Fábio Santos <fabiosantosart@gmail.com> - 2013-05-13 22:48 +0100
        Re: Differences of "!=" operator behavior in python3 and python2 [ bug? ] Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-05-13 23:53 +0100
        Re: Differences of "!=" operator behavior in python3 and python2 [ bug? ] Dave Angel <davea@davea.name> - 2013-05-13 19:22 -0400
          Re: Differences of "!=" operator behavior in python3 and python2 [ bug? ] Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-05-14 05:09 +0000
            Re: Differences of "!=" operator behavior in python3 and python2 [ bug? ] Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-05-14 19:01 -0400
              Re: Differences of "!=" operator behavior in python3 and python2 [ bug? ] Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-05-15 00:15 +0000
                Re: Differences of "!=" operator behavior in python3 and python2 [ bug? ] Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-05-14 22:20 -0400
        Re: Differences of "!=" operator behavior in python3 and python2 [ bug? ] Andrew Berg <bahamutzero8825@gmail.com> - 2013-05-13 18:27 -0500
        Re: Differences of "!=" operator behavior in python3 and python2 [ bug? ] Ian Kelly <ian.g.kelly@gmail.com> - 2013-05-13 17:32 -0600
        Re: Differences of "!=" operator behavior in python3 and python2 [ bug? ] Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-05-14 05:21 +0000
          Re: Differences of "!=" operator behavior in python3 and python2 [ bug? ] Alister <alister.ware@ntlworld.com> - 2013-05-15 14:41 +0000
        Re: Differences of "!=" operator behavior in python3 and python2 [ bug? ] Chris Angelico <rosuav@gmail.com> - 2013-05-14 17:31 +1000

csiph-web