Re: checking if two things do not equal None

2014-03-31 Thread Jeremy Sanders
contact.tri...@gmail.com wrote: if (a, b) != (None, None): or if a != None != b: Preference? Pros? Cons? Alternatives? I couldn't see anyone else give this, but I like if None not in (a, b): pass Jeremy -- https://mail.python.org/mailman/listinfo/python-list

Re: checking if two things do not equal None

2014-03-31 Thread Abe
I couldn't see anyone else give this, but I like if None not in (a, b): I did. I am now considering: if None not in (a,b): or if (a is not None) and (b is not None): However, I decided to just turn the two parameters into one (sequence), since they were logically grouped anyhow. --

Re: checking if two things do not equal None

2014-03-31 Thread Moritz Emanuel Beber
On 31/03/14 19:28, Abe wrote: I couldn't see anyone else give this, but I like if None not in (a, b): I did. I am now considering: if None not in (a,b): or if (a is not None) and (b is not None): That's just if not (a is None or b is None): but you seem to have found your way. However, I

Re: checking if two things do not equal None

2014-03-30 Thread Steven D'Aprano
On Sat, 29 Mar 2014 19:54:09 -0700, Rustom Mody wrote: On Sunday, March 30, 2014 8:09:45 AM UTC+5:30, Roy Smith wrote: I have no particular problem with x 2 y because it fits the same pattern. But, if you show me a != None != b: my brain just goes into overload. Honestly, I

Re: checking if two things do not equal None

2014-03-30 Thread Chris Angelico
On Sun, Mar 30, 2014 at 4:54 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Sun, 30 Mar 2014 13:15:18 +1100, Chris Angelico wrote: Chained comparisons where you're checking a single variable against two constants make perfect sense: 2 x 5 Chained comparisons where you

Re: checking if two things do not equal None

2014-03-30 Thread Gregory Ewing
Roy Smith wrote: But, if you show me a != None != b: my brain just goes into overload. Chained comparisons get weird with not-equal operators. If you see a == b == c then it implies that a == c, but a != b != c does *not* imply that a != c. At least it doesn't in Python; I've never

Re: checking if two things do not equal None

2014-03-30 Thread Ben Finney
Chris Angelico ros...@gmail.com writes: The problem isn't that I can't see what the comparisons are. It makes very good sense to bound a variable within constants; but you already know exactly where 2 is on the number line, so asking Is 2 between these two variables seems a bit odd. Maybe

Re: checking if two things do not equal None

2014-03-30 Thread Chris Angelico
On Sun, Mar 30, 2014 at 5:52 PM, Ben Finney ben+pyt...@benfinney.id.au wrote: Chris Angelico ros...@gmail.com writes: The problem isn't that I can't see what the comparisons are. It makes very good sense to bound a variable within constants; but you already know exactly where 2 is on the

Re: checking if two things do not equal None

2014-03-30 Thread Marko Rauhamaa
Gregory Ewing greg.ew...@canterbury.ac.nz: a != b != c does *not* imply that a != c. At least it doesn't in Python; I've never seen any mathematicians write that, so I don't know what they would make of it. Any resemblance between mathematics notation and Python is purely coincidental. I

Re: checking if two things do not equal None

2014-03-30 Thread Roy Smith
In article 5337b4e4$0$29994$c3e8da3$54964...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: I think Johannes got it right: boolean logic is easier to reason about when there is a minimum of nots. I used to do a lot of digital logic design. In certain logic

Re: checking if two things do not equal None

2014-03-30 Thread MRAB
On 2014-03-30 13:21, Roy Smith wrote: In article 5337b4e4$0$29994$c3e8da3$54964...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: I think Johannes got it right: boolean logic is easier to reason about when there is a minimum of nots. I used to do a lot of

Re: checking if two things do not equal None

2014-03-30 Thread Gregory Ewing
Roy Smith wrote: Adding to the confusion, many designs would use active low logic, which means a 1 was represented by a low voltage, and a 0 by a high voltage. So, you quickly end up with gibberish like, not active low clear nand not active low enable clock. There are ways of dealing with

checking if two things do not equal None

2014-03-29 Thread contact . trigon
if (a, b) != (None, None): or if a != None != b: Preference? Pros? Cons? Alternatives? :D -- https://mail.python.org/mailman/listinfo/python-list

Re: checking if two things do not equal None

2014-03-29 Thread Steven D'Aprano
On Sat, 29 Mar 2014 11:56:50 -0700, contact.trigon wrote: if (a, b) != (None, None): or if a != None != b: Preference? Pros? Cons? Alternatives? Do you actually want to check for arbitrary objects which may claim to equal None, or do you want to check for objects which are None? Nearly

Re: checking if two things do not equal None

2014-03-29 Thread Lele Gaifax
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info writes: if not (a is b is None): ... Or if you prefer: if a is not b is not None: ... 1 is not 1 is not None False So definitely the former! ciao, lele. -- nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri real:

Re: checking if two things do not equal None

2014-03-29 Thread contact . trigon
Do you actually want to check for arbitrary objects which may claim to equal None, or do you want to check for objects which are None? Arbitrary objects are not a concern. if not (a is b is None): ... if a is not b is not None: ... Thanks for the examples. --

Re: checking if two things do not equal None

2014-03-29 Thread Johannes Bauer
On 29.03.2014 20:05, Steven D'Aprano wrote: On Sat, 29 Mar 2014 11:56:50 -0700, contact.trigon wrote: if (a, b) != (None, None): or if a != None != b: Preference? Pros? Cons? Alternatives? if not (a is b is None): ... Or if you prefer: if a is not b is not None: ... Is this an

Re: checking if two things do not equal None

2014-03-29 Thread Roy Smith
In article lh7cb4$ntu$2...@news.albasani.net, Johannes Bauer dfnsonfsdu...@gmx.de wrote: On 29.03.2014 20:05, Steven D'Aprano wrote: On Sat, 29 Mar 2014 11:56:50 -0700, contact.trigon wrote: if (a, b) != (None, None): or if a != None != b: Preference? Pros? Cons? Alternatives?

Re: checking if two things do not equal None

2014-03-29 Thread Dave Angel
Roy Smith r...@panix.com Wrote in message: In article lh7cb4$ntu$2...@news.albasani.net, Johannes Bauer dfnsonfsdu...@gmx.de wrote: On 29.03.2014 20:05, Steven D'Aprano wrote: On Sat, 29 Mar 2014 11:56:50 -0700, contact.trigon wrote: if (a, b) != (None, None): or if a != None !=

Re: checking if two things do not equal None

2014-03-29 Thread Johannes Bauer
On 29.03.2014 22:07, Roy Smith wrote: I agree with that. But if (a, b) != (None, None): seems pretty straight-forward to me too. In fact, if anything, it seems easier to understand than if (a is not None) or (b is not None): Yes, probably. I liked the original, too. If I were

Re: checking if two things do not equal None

2014-03-29 Thread Johannes Bauer
On 29.03.2014 22:55, Johannes Bauer wrote: if (a is not None) or (b is not None): Yes, probably. I liked the original, too. If I were writing the code, I'd probably try to aim to invert the condition though and simply do if (a is None) and (b is None) Which is pretty easy to understand

Re: checking if two things do not equal None

2014-03-29 Thread Tim Chase
On 2014-03-29 17:07, Roy Smith wrote: if (a is not None) or (b is not None): is immediately understandable by everyone? I agree with that. But if (a, b) != (None, None): seems pretty straight-forward to me too. In fact, if anything, it seems easier to understand than And

Re: checking if two things do not equal None

2014-03-29 Thread Roy Smith
On Mar 29, 2014, at 6:36 PM, Tim Chase wrote: And for cases where you have more than one or two things to test for None-itude, you could use if all(x is None for x in [a, b, c, d]): do_something_if_theyre_all_None() I might have written that as: if set([a, b, c, d]) == set(None)

Re: checking if two things do not equal None

2014-03-29 Thread Tim Chase
On 2014-03-29 18:41, Roy Smith wrote: On Mar 29, 2014, at 6:36 PM, Tim Chase wrote: And for cases where you have more than one or two things to test for None-itude, you could use if all(x is None for x in [a, b, c, d]): do_something_if_theyre_all_None() I might have written

Re: checking if two things do not equal None

2014-03-29 Thread Roy Smith
In article mailman.8703.1396133206.18130.python-l...@python.org, Tim Chase t...@thechases.com wrote: On 2014-03-29 18:41, Roy Smith wrote: On Mar 29, 2014, at 6:36 PM, Tim Chase wrote: And for cases where you have more than one or two things to test for None-itude, you could use

Re: checking if two things do not equal None

2014-03-29 Thread Terry Reedy
On 3/29/2014 2:56 PM, contact.tri...@gmail.com wrote: if (a, b) != (None, None): or if a != None != b: Preference? Pros? Cons? Alternatives? if a is not None is not b == if a is not None and None is not b == if a is not None and b is not None which is what I would write if not trying to be

Re: checking if two things do not equal None

2014-03-29 Thread Chris Angelico
On Sun, Mar 30, 2014 at 9:46 AM, Tim Chase t...@thechases.com wrote: Though am I correct that your iteration tests for equality, while mine tests for identity? Also, my version bails early in the event quitting early is possible. That's particularly useful in the case of doing something like

Re: checking if two things do not equal None

2014-03-29 Thread contact . trigon
Thanks everyone; it has been very educational. Dave Angel: ...we'll find that two of the alternatives are not even equivalent. That helped me realize (a,b) != (None, None) is not correct for the function. It's a case where two parameters have None as the default argument. What I want is to

Re: checking if two things do not equal None

2014-03-29 Thread Ethan Furman
On 03/29/2014 02:01 PM, Johannes Bauer wrote: On 29.03.2014 20:05, Steven D'Aprano wrote: On Sat, 29 Mar 2014 11:56:50 -0700, contact.trigon wrote: if (a, b) != (None, None): or if a != None != b: Preference? Pros? Cons? Alternatives? if not (a is b is None): ... Or if you prefer: if a

Re: checking if two things do not equal None

2014-03-29 Thread Tim Chase
On 2014-03-30 10:17, Chris Angelico wrote: On Sun, Mar 30, 2014 at 9:46 AM, Tim Chase t...@thechases.com wrote: Though am I correct that your iteration tests for equality, while mine tests for identity? Also, my version bails early in the event quitting early is possible. That's

Re: checking if two things do not equal None

2014-03-29 Thread Chris Angelico
On Sun, Mar 30, 2014 at 12:19 PM, Tim Chase python.l...@tim.thechases.com wrote: On 2014-03-30 10:17, Chris Angelico wrote: On Sun, Mar 30, 2014 at 9:46 AM, Tim Chase t...@thechases.com wrote: Though am I correct that your iteration tests for equality, while mine tests for identity? Also, my

Re: checking if two things do not equal None

2014-03-29 Thread Steven D'Aprano
On Sat, 29 Mar 2014 17:07:20 -0400, Roy Smith wrote: I certainly agree that things like if a is not b is not None: ... belong in an obfuscated coding contest. Apart from the fact that I got it wrong (that's what happens when I post at 6am after being up all night, thanks for the

Re: checking if two things do not equal None

2014-03-29 Thread Chris Angelico
On Sun, Mar 30, 2014 at 1:04 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Sat, 29 Mar 2014 17:07:20 -0400, Roy Smith wrote: I certainly agree that things like if a is not b is not None: ... belong in an obfuscated coding contest. Apart from the fact that I got it

Re: checking if two things do not equal None

2014-03-29 Thread Steven D'Aprano
On Sat, 29 Mar 2014 17:36:55 -0500, Tim Chase wrote: And for cases where you have more than one or two things to test for None-itude, you could use if all(x is None for x in [a, b, c, d]): do_something_if_theyre_all_None() or if all(x is not None for x in [a, b, c, d]):

Re: checking if two things do not equal None

2014-03-29 Thread Roy Smith
In article mailman.8709.1396145720.18130.python-l...@python.org, Chris Angelico ros...@gmail.com wrote: Chained comparisons where you're checking a single variable against two constants make perfect sense: 2 x 5 Chained comparisons where you check a single constant against two

Re: checking if two things do not equal None

2014-03-29 Thread Roy Smith
In article 5337807b$0$29994$c3e8da3$54964...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: a is b is c is None And we are all together. See how they run like pigs from a gun, see how they fly. -- https://mail.python.org/mailman/listinfo/python-list

Re: checking if two things do not equal None

2014-03-29 Thread Rustom Mody
On Sunday, March 30, 2014 8:09:45 AM UTC+5:30, Roy Smith wrote: I have no particular problem with x 2 y because it fits the same pattern. But, if you show me a != None != b: my brain just goes into overload. Honestly, I don't even know what that means. My brain keeps trying to

Re: checking if two things do not equal None

2014-03-29 Thread Zachary Ware
On March 29, 2014 9:43:00 PM CDT, Roy Smith r...@panix.com wrote: In article 5337807b$0$29994$c3e8da3$54964...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: a is b is c is None And we are all together. See how they run like pigs from a gun, see how they

Re: checking if two things do not equal None

2014-03-29 Thread Steven D'Aprano
On Sun, 30 Mar 2014 13:15:18 +1100, Chris Angelico wrote: On Sun, Mar 30, 2014 at 1:04 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Sat, 29 Mar 2014 17:07:20 -0400, Roy Smith wrote: I certainly agree that things like if a is not b is not None: ... belong in an