Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.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.012 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'subject:object': 0.07; 'assert': 0.09; 'covered.': 0.09; 'subject:None': 0.09; '25,': 0.12; '"=="': 0.16; 'boolean': 0.16; 'complicating': 0.16; 'expression:': 0.16; 'hudson': 0.16; 'none"': 0.16; 'otoh,': 0.16; 'unequal': 0.16; 'cc:addr:python-list': 0.16; 'looked': 0.16; 'wrote:': 0.18; 'thanks,': 0.18; 'cc:no real name:2**0': 0.20; 'subject:not': 0.21; 'maybe': 0.21; 'dec': 0.22; "doesn't": 0.22; 'header:In-Reply-To:1': 0.22; 'cc:2**0': 0.24; '(my': 0.24; 'code': 0.25; 'url:mailman': 0.28; 'message-id:@mail.gmail.com': 0.28; 'weird': 0.29; 'looks': 0.29; 'cc:addr:python.org': 0.29; 'pm,': 0.29; 'seem': 0.30; 'none,': 0.30; 'received:209.85.210.46': 0.30; 'received:mail- pz0-f46.google.com': 0.30; 'skip:\xc2 20': 0.30; 'subject:Test': 0.30; 'sun,': 0.30; 'hi,': 0.32; 'url:listinfo': 0.32; 'instead': 0.33; 'points': 0.34; 'implies': 0.34; 'issue': 0.35; 'response': 0.35; 'url:python': 0.36; 'problem.': 0.36; 'none': 0.37; 'but': 0.37; 'run': 0.37; 'received:google.com': 0.37; 'received:209.85': 0.38; 'getting': 0.38; 'url:org': 0.39; 'should': 0.39; 'being': 0.39; "it's": 0.40; 'received:209': 0.40; '2011': 0.61; 'worth': 0.61; 'your': 0.61; 'believe': 0.65; 'here': 0.65; 'piece': 0.66; 'realized': 0.73; 'exclusive': 0.79; 'to:addr:yahoo.com': 0.83; 'implication.': 0.84; 'glance': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=g9tue/Y/MY1cn0y8xQ97ZgRa4CEl7/T6/YyJIEug4C0=; b=W57Xcf4gdxx035iHKjWANCk2PhBiXZqjKqa+KbZI1u+eWqQ5nAxAymKDGC7XVGbEt8 dooVgGnnX2IruZU5muVMJHCrr3YLYfz/8YDNfB3pSpIRyjy1dP8EV+3XECaO3UqTogxE LQTujep2WKetDpoL+eZwsq6zW+NV507HiR364= MIME-Version: 1.0 In-Reply-To: References: <0d80ce25-9e65-4216-b26c-b8ee40f989a3@q9g2000yqe.googlegroups.com> From: Devin Jeanpierre Date: Sun, 25 Dec 2011 19:06:50 -0500 Subject: Re: Test None for an object that does not implement == To: Larry Hudson Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 55 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1324858055 news.xs4all.nl 6852 [2001:888:2000:d::a6]:44380 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:17931 > At first glance this looked like it should be a simple boolean "and", but > then I realized that when a and c are both unequal to None, the result wo= uld > also be True. This implies the logical approach would be exclusive-or (^= ). Among booleans, "!=3D" is exclusive or and "=3D=3D" is its negation. I don'= t see the point of complicating the formula to use ^. (related: <=3D is implication. Which is sad, because the arrow points the wrong way!) The issue here is that "=3D=3D None" is being used instead of "is None", but I believe that's been covered. Your response doesn't include it, so maybe it's worth restating. -- Devin On Sun, Dec 25, 2011 at 6:45 PM, Larry Hudson wrote: > On 12/24/2011 11:09 PM, GZ wrote: >> >> Hi, >> >> I run into a weird problem. I have a piece of code that looks like the >> following: >> >> f(...., a=3DNone, c=3DNone): >> =C2=A0 =C2=A0 assert =C2=A0(a=3D=3DNone)=3D=3D(c=3D=3DNone) >> > <...> > > At first glance this looked like it should be a simple boolean "and", but > then I realized that when a and c are both unequal to None, the result wo= uld > also be True. =C2=A0This implies the logical approach would be exclusive-= or (^). > =C2=A0Try this expression: > > =C2=A0 =C2=A0 not ((a=3D=3DNone) ^ (c=3D=3DNone)) > > OTOH, if what you really want is simply to check that both are None (my > first impression), then it's simply: > > =C2=A0 =C2=A0 (a=3D=3DNone) and (c=3D=3DNone) > > Most of the replies you're getting here seem unnecessarily complicated. > >> Thanks, >> gz > > > =C2=A0 =C2=A0-=3D- Larry -=3D- > -- > http://mail.python.org/mailman/listinfo/python-list