Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'operator': 0.03; 'output': 0.05; '"""': 0.07; '-*-': 0.07; 'subject:bug': 0.07; 'utf-8': 0.07; 'advance': 0.07; 'coding:': 0.09; 'val': 0.09; 'python': 0.11; 'def': 0.12; 'bug': 0.12; '__future__': 0.16; 'reproduce': 0.16; 'subject:python3': 0.16; 'import': 0.22; 'message- id:@mail.gmail.com': 0.30; 'code': 0.31; 'class': 0.32; 'to:name :python-list': 0.33; 'skip:_ 10': 0.34; 'received:google.com': 0.35; 'false': 0.36; 'thanks': 0.36; 'to:addr:python-list': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; 'skip:u 10': 0.60; 'situation': 0.65; 'behavior': 0.77 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:date:message-id:subject:from:to :content-type; bh=D6MvZNA3SPzefyV12aCamQYy7759ME5rJ2Lvfnz5ptg=; b=snrm7Ybla47zSuCOooBgns+erYLEfMwcohUWNN4gJnw18G+OsgFCHJhndGbuqewaGW W4jq0rsdJg9pxz/tX+mkmttg9OBBv3SlJ31LEcASFyc34u+PnOjjNYVD7TGiIGFAHcRh 5ywnGQF0zFkE/wmnE6V3maGBIoTzQ60DAz58nvUfskcO7MeEKnCardjr2rcGc6f8Oam9 zmPxKB8uJvlcJVCRDCMdDaXmzKxwXlI1Erc2bDgYyVxQw/TsTh0RLaXnF3eTw4ueRczR O5P1rL4U6gWK+QeNtTSSn7GcjnSCI3TQrBBcMKd3+EgeKKQK5SLaD7NPsm1ajTEzOmiO YBmw== MIME-Version: 1.0 X-Received: by 10.68.237.106 with SMTP id vb10mr20868242pbc.131.1368400996468; Sun, 12 May 2013 16:23:16 -0700 (PDT) Date: Mon, 13 May 2013 05:23:16 +0600 Subject: Differences of "!=" operator behavior in python3 and python2 [ bug? ] From: "Mr. Joe" To: python-list Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 40 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1368401007 news.xs4all.nl 15895 [2001:888:2000:d::a6]:50355 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:45210 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