Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #17931
| References | <0d80ce25-9e65-4216-b26c-b8ee40f989a3@q9g2000yqe.googlegroups.com> <rPmdnSvo4MEbKGrTnZ2dnUVZ5g-dnZ2d@giganews.com> |
|---|---|
| From | Devin Jeanpierre <jeanpierreda@gmail.com> |
| Date | 2011-12-25 19:06 -0500 |
| Subject | Re: Test None for an object that does not implement == |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4082.1324858055.27778.python-list@python.org> (permalink) |
> 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 would > also be True. This implies the logical approach would be exclusive-or (^). Among booleans, "!=" is exclusive or and "==" is its negation. I don't see the point of complicating the formula to use ^. (related: <= is implication. Which is sad, because the arrow points the wrong way!) The issue here is that "== 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 <orgnut@yahoo.com> 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=None, c=None): >> assert (a==None)==(c==None) >> > <...> > > 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 would > also be True. This implies the logical approach would be exclusive-or (^). > Try this expression: > > not ((a==None) ^ (c==None)) > > OTOH, if what you really want is simply to check that both are None (my > first impression), then it's simply: > > (a==None) and (c==None) > > Most of the replies you're getting here seem unnecessarily complicated. > >> Thanks, >> gz > > > -=- Larry -=- > -- > http://mail.python.org/mailman/listinfo/python-list
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Test None for an object that does not implement == GZ <zyzhu2000@gmail.com> - 2011-12-24 23:09 -0800
Re: Test None for an object that does not implement == Paul Rubin <no.email@nospam.invalid> - 2011-12-24 23:28 -0800
Re: Test None for an object that does not implement == Nobody <nobody@nowhere.com> - 2011-12-25 09:38 +0000
Re: Test None for an object that does not implement == Lie Ryan <lie.1296@gmail.com> - 2011-12-25 22:10 +1100
Re: Test None for an object that does not implement == Roy Smith <roy@panix.com> - 2011-12-25 08:17 -0500
Re: Test None for an object that does not implement == Chris Angelico <rosuav@gmail.com> - 2011-12-26 00:35 +1100
Re: Test None for an object that does not implement == Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-12-25 13:48 +0000
Re: Test None for an object that does not implement == Chris Angelico <rosuav@gmail.com> - 2011-12-26 01:04 +1100
Re: Test None for an object that does not implement == Christian Heimes <lists@cheimes.de> - 2011-12-26 01:37 +0100
Re: Test None for an object that does not implement == Roy Smith <roy@panix.com> - 2011-12-25 09:13 -0500
Re: Test None for an object that does not implement == Chris Angelico <rosuav@gmail.com> - 2011-12-26 01:23 +1100
Re: Test None for an object that does not implement == Lie Ryan <lie.1296@gmail.com> - 2011-12-26 04:13 +1100
Re: Test None for an object that does not implement == Ian Kelly <ian.g.kelly@gmail.com> - 2011-12-25 19:02 -0700
Re: Test None for an object that does not implement == Ethan Furman <ethan@stoneleaf.us> - 2011-12-25 20:26 -0800
Re: Test None for an object that does not implement == Larry Hudson <orgnut@yahoo.com> - 2011-12-25 15:45 -0800
Re: Test None for an object that does not implement == Devin Jeanpierre <jeanpierreda@gmail.com> - 2011-12-25 19:06 -0500
Re: Test None for an object that does not implement == Roy Smith <roy@panix.com> - 2011-12-25 19:27 -0500
Re: Test None for an object that does not implement == Devin Jeanpierre <jeanpierreda@gmail.com> - 2011-12-25 19:58 -0500
Re: Test None for an object that does not implement == Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-12-26 00:52 +0000
Re: Test None for an object that does not implement == Ethan Furman <ethan@stoneleaf.us> - 2011-12-25 20:27 -0800
Re: Test None for an object that does not implement == Devin Jeanpierre <jeanpierreda@gmail.com> - 2011-12-26 00:22 -0500
Re: Test None for an object that does not implement == Roy Smith <roy@panix.com> - 2011-12-26 08:43 -0500
Re: Test None for an object that does not implement == Paul Rudin <paul.nospam@rudin.co.uk> - 2011-12-26 14:33 +0000
Re: Test None for an object that does not implement == Ethan Furman <ethan@stoneleaf.us> - 2011-12-26 09:14 -0800
csiph-web