Re: easy question on parsing python: "is not None"

2010-08-12 Thread Steven D'Aprano
On Thu, 12 Aug 2010 19:52:07 -0700, Matt Schinckel wrote: a = "hello" b = "hello" a is b > True > > Ooh, that looks dangerous. Are they the same object? You don't need another test to know that they are the same object. The `is` operator does exactly that: a is b *only* if a and

Re: easy question on parsing python: "is not None"

2010-08-12 Thread Terry Reedy
On 8/12/2010 10:52 PM, Matt Schinckel wrote: a = "hello" b = "hello" a is b True Ooh, that looks dangerous. Only for mutable objects Are they the same object? Yes. a += "o" This is equivalent to a = a+"o". The expression creates a new object. The assignment binds the object to name

Re: easy question on parsing python: "is not None"

2010-08-12 Thread Matt Schinckel
On Aug 6, 8:15 am, "Rhodri James" wrote: > On Thu, 05 Aug 2010 17:07:53 +0100, wheres pythonmonks   > > wrote: > > Well, I am not convinced of the equivalence of not None and true: [snip] > >>> "spam, eggs, chips and spam" is "spam, eggs, chips and spam" > True > >>> a = "spam, eggs, chips and sp

Re: easy question on parsing python: "is not None"

2010-08-10 Thread Jean-Michel Pichavant
Ben Finney wrote: Peter Pearson writes: Hey, that's a cute example, but . . . what a trap! Is it possible to document the use-the-object-not-the-string requirement loudly enough that people won't get caught? Don't use strings for such values. The data isn't going to be used, so there

Re: easy question on parsing python: "is not None"

2010-08-09 Thread Ben Finney
"saeed.gnu" writes: > "x is y" means "id(y) == id(y)" > "x is not y" means "id(x) != id(x)" > "x is not None" means "id(x) != id(None)" No, the meanings are different. The behaviour might, or might not, be the same. The operators are different *because* the meanings are dif

Re: easy question on parsing python: "is not None"

2010-08-09 Thread Michael Torrie
On 08/09/2010 06:11 AM, saeed.gnu wrote: > On Aug 9, 3:41 pm, "saeed.gnu" wrote: >> "x is y" means "id(y) == id(y)" >> "x is not y" means "id(x) != id(x)" >> "x is not None" means "id(x) != id(None)" >> >> "x is not None" is a really silly statement!! because id(None) and id

Re: easy question on parsing python: "is not None"

2010-08-09 Thread Gabriel Genellina
En Mon, 09 Aug 2010 08:41:23 -0300, saeed.gnu escribió: "x is y" means "id(y) == id(y)" "x is not y" means "id(x) != id(x)" No; consider this: py> id([])==id([]) True py> [] is [] False Comparing id's is the same as using the is operator only if you can guarantee that

Re: easy question on parsing python: "is not None"

2010-08-09 Thread Terry Reedy
On 8/9/2010 7:41 AM, saeed.gnu wrote: "x is y" means "id(y) == id(y)" "x is not y" means "id(x) != id(x)" "x is not None" means "id(x) != id(None)" "x is not None" is a really silly statement!! Wrong. It is exactly right when that is what one means and is the STANDARD I

Re: easy question on parsing python: "is not None"

2010-08-09 Thread Nobody
On Mon, 09 Aug 2010 04:41:23 -0700, saeed.gnu wrote: > "x is not None" is a really silly statement!! because id(None) and id > of any constant object is not predictable! I don't know whay people > use "is" instead of "==". you should write "if x!=None" instead of "x > is not None" No, you should

Re: easy question on parsing python: "is not None"

2010-08-09 Thread Dave Angel
saeed.gnu wrote: On Aug 9, 3:41 pm, "saeed.gnu" wrote: "x is y" means "id(y) =id(y)" "x is not y" means "id(x) !=d(x)" "x is not None" means "id(x) !=d(None)" "x is not None" is a really silly statement!! because id(None) and id of any constant object is not predictab

Re: easy question on parsing python: "is not None"

2010-08-09 Thread saeed.gnu
On Aug 9, 3:41 pm, "saeed.gnu" wrote: > "x is y"          means   "id(y) == id(y)" > "x is not y"      means   "id(x) != id(x)" > "x is not None"   means   "id(x) != id(None)" > > "x is not None"  is a really silly statement!! because id(None) and id > of any constant object is not predictable! I

Re: easy question on parsing python: "is not None"

2010-08-09 Thread saeed.gnu
"x is y" means "id(y) == id(y)" "x is not y" means "id(x) != id(x)" "x is not None" means "id(x) != id(None)" "x is not None" is a really silly statement!! because id(None) and id of any constant object is not predictable! I don't know whay people use "is" instead of "==". y

Re: easy question on parsing python: "is not None"

2010-08-09 Thread Bruno Desthuilliers
Gregory Ewing a écrit : Ethan Furman wrote: Instead of using 'is' use '=='. Maybe not as cute, but definitely more robust! It's also just as efficient if you use strings that resemble identifiers, because they will be interned, Remember : this IS an implementation detail. -- http://mail.p

avoiding top posts in gmail [was easy question on parsing python: "is not None"]

2010-08-09 Thread Cameron Simpson
On 05Aug2010 12:07, wheres pythonmonks wrote: | P.S. Sorry for the top-post -- is there a way to not do top posts from | gmail? I haven't used usenet since tin. The standard way is with attitude: view having your cursor at the top not as forcing you to top post but as an opportunity to start pru

Re: easy question on parsing python: "is not None"

2010-08-08 Thread Albert van der Horst
In article <8c2uiufg9...@mid.individual.net>, Peter Pearson wrote: >On Fri, 06 Aug 2010 15:37:04 +0200, Stefan Schwarzer wrote: >[snip] >> I can imagine a case where you might want to compare a >> string with `is`: >> >> FORWARD = "forward" >> BACKWARD = "backward" >> >> ... >> >>

Re: easy question on parsing python: "is not None"

2010-08-08 Thread Stefan Schwarzer
Hi Ben, On 2010-08-08 01:16, Ben Finney wrote: > Don't use strings for such values. The data isn't going to be used, so > there's no sense using a semantically rich data type like a string. > > Instead, use an ‘object’ instance; then, the only way to get a binding > that will compare equal is to

Re: easy question on parsing python: "is not None"

2010-08-07 Thread Ben Finney
Peter Pearson writes: > Hey, that's a cute example, but . . . what a trap! Is it possible to > document the use-the-object-not-the-string requirement loudly enough > that people won't get caught? Don't use strings for such values. The data isn't going to be used, so there's no sense using a sema

Re: easy question on parsing python: "is not None"

2010-08-07 Thread Thomas Jollans
On 08/07/2010 09:44 AM, Gabriel Genellina wrote: > En Sat, 07 Aug 2010 04:04:06 -0300, Stefan Schwarzer > escribió: >> On 2010-08-07 00:28, Steven D'Aprano wrote: > >>> Actually, yes, equality is implemented with a short-cut > that checks for >>> identity first. That makes something like: >>> [..

Re: easy question on parsing python: "is not None"

2010-08-07 Thread Steven D'Aprano
On Sat, 07 Aug 2010 14:28:19 +1000, Ben Finney wrote: > Steven D'Aprano writes: > >> On Thu, 05 Aug 2010 12:07:53 -0400, wheres pythonmonks wrote: >> >> > P.S. Sorry for the top-post -- is there a way to not do top posts >> > from gmail? I haven't used usenet since tin. >> >> Er, surely you can

Re: easy question on parsing python: "is not None"

2010-08-07 Thread Gabriel Genellina
En Sat, 07 Aug 2010 04:04:06 -0300, Stefan Schwarzer escribió: On 2010-08-07 00:28, Steven D'Aprano wrote: Actually, yes, equality is implemented with a short-cut that checks for identity first. That makes something like: [...] Oops, I didn't realize that the OP had mentioned the identit

Re: easy question on parsing python: "is not None"

2010-08-07 Thread Stefan Schwarzer
Hi Steven, On 2010-08-07 00:28, Steven D'Aprano wrote: > On Fri, 06 Aug 2010 15:37:04 +0200, Stefan Schwarzer wrote: >>> Plus, I believe the >>> "==" operator will check if the variables point to the same object. >> >> No, that's what `is` is for. > > Actually, yes, equality is implemented with a

Re: easy question on parsing python: "is not None"

2010-08-06 Thread Ben Finney
Steven D'Aprano writes: > On Thu, 05 Aug 2010 12:07:53 -0400, wheres pythonmonks wrote: > > > P.S. Sorry for the top-post -- is there a way to not do top posts > > from gmail? I haven't used usenet since tin. > > Er, surely you can just move the cursor before you start typing??? I like to think

Re: easy question on parsing python: "is not None"

2010-08-06 Thread Gregory Ewing
Steven D'Aprano wrote: Generally, when testing for None, you actually want None and not some look-alike that merely tests equal to None. That's true, although I can't think of a use case for an object that compares equal to None but isn't -- except for obfuscated code competition entries and m

Re: easy question on parsing python: "is not None"

2010-08-06 Thread Gregory Ewing
Ethan Furman wrote: Instead of using 'is' use '=='. Maybe not as cute, but definitely more robust! It's also just as efficient if you use strings that resemble identifiers, because they will be interned, so the comparison will end up just doing an indentity test anyway. -- Greg -- http://mai

Re: easy question on parsing python: "is not None"

2010-08-06 Thread Steven D'Aprano
On Fri, 06 Aug 2010 11:42:39 +0200, Jean-Michel Pichavant wrote: > Steven D'Aprano wrote: >> On Thu, 05 Aug 2010 12:07:53 -0400, wheres pythonmonks wrote: >> >>> P.S. Sorry for the top-post -- is there a way to not do top posts from >>> gmail? I haven't used usenet since tin. >>> >> Er, sure

Re: easy question on parsing python: "is not None"

2010-08-06 Thread Steven D'Aprano
On Fri, 06 Aug 2010 15:37:04 +0200, Stefan Schwarzer wrote: >> Plus, I believe the >> "==" operator will check if the variables point to the same object. > > No, that's what `is` is for. Actually, yes, equality is implemented with a short-cut that checks for identity first. That makes something

Re: easy question on parsing python: "is not None"

2010-08-06 Thread Steven D'Aprano
On Fri, 06 Aug 2010 05:28:40 -0700, DG wrote: > I've always thought of it as you don't compare strings with "is", you > *should* use == The reasoning is that you don't know if that string > instance is the only one in memory. This is excellent advice. I won't say that there is "never" a use-case

Re: easy question on parsing python: "is not None"

2010-08-06 Thread Steven D'Aprano
On Fri, 06 Aug 2010 17:20:30 +, Peter Pearson wrote: > On Fri, 06 Aug 2010 15:37:04 +0200, Stefan Schwarzer wrote: [snip] >> I can imagine a case where you might want to compare a string with >> `is`: >> >> FORWARD = "forward" >> BACKWARD = "backward" [...] >> Actually, I've never seen

Re: easy question on parsing python: "is not None"

2010-08-06 Thread Ethan Furman
Stefan Schwarzer wrote: Hello Peter, On 2010-08-06 19:20, Peter Pearson wrote: On Fri, 06 Aug 2010 15:37:04 +0200, Stefan Schwarzer wrote: [snip] I can imagine a case where you might want to compare a string with `is`: FORWARD = "forward" BACKWARD = "backward" ... def func(d

Re: easy question on parsing python: "is not None"

2010-08-06 Thread Stefan Schwarzer
Hello Peter, On 2010-08-06 19:20, Peter Pearson wrote: > On Fri, 06 Aug 2010 15:37:04 +0200, Stefan Schwarzer wrote: > [snip] >> I can imagine a case where you might want to compare a >> string with `is`: >> >> FORWARD = "forward" >> BACKWARD = "backward" >> >> ... >> >> def func(d

Re: easy question on parsing python: "is not None"

2010-08-06 Thread Terry Reedy
On 8/6/2010 5:27 AM, Richard D. Moores wrote: So there would be a different implementation for each operating system? One for Windows, one for linux? Or one for Vista and one for XP? I'm just trying to clarify what is meant by "implementation". Different version of CPython (that string cachin

Re: easy question on parsing python: "is not None"

2010-08-06 Thread Peter Pearson
On Fri, 06 Aug 2010 15:37:04 +0200, Stefan Schwarzer wrote: [snip] > I can imagine a case where you might want to compare a > string with `is`: > > FORWARD = "forward" > BACKWARD = "backward" > > ... > > def func(direction=FORWARD): > if direction is FORWARD: > .

Re: easy question on parsing python: "is not None"

2010-08-06 Thread Stefan Schwarzer
Hi DG, On 2010-08-06 14:28, DG wrote: > I've always thought of it as you don't compare strings with "is", you > *should* use == The reasoning is that you don't know if that string > instance is the only one in memory. I've heard as an implementation > detail, since strings are immutable, that Py

Re: easy question on parsing python: "is not None"

2010-08-06 Thread DG
On Aug 6, 2:32 am, Bruno Desthuilliers wrote: > Richard D. Moores a écrit : > > > > > On Thu, Aug 5, 2010 at 16:15, Rhodri James > > wrote: > >> On Thu, 05 Aug 2010 17:07:53 +0100, wheres pythonmonks > >> wrote: > > >> You're not testing for equivalence there, you're testing for identity.   > >

Re: easy question on parsing python: "is not None"

2010-08-06 Thread Vito 'ZeD' De Tullio
Richard D. Moores wrote: > So there would be a different implementation for each operating > system? One for Windows, one for linux? Or one for Vista and one for > XP? I'm just trying to clarify what is meant by "implementation". there are dozillions of "implementation" of python: one for each r

Re: easy question on parsing python: "is not None"

2010-08-06 Thread Roald de Vries
On Aug 6, 2010, at 9:25 AM, Bruno Desthuilliers wrote: Roald de Vries a écrit : 'not None' first casts None to a bool, and then applies 'not', so 'x is not None' means 'x is True'. Obviously plain wrong : Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) [GCC 4.3.3] on linux2 Type "help"

Re: easy question on parsing python: "is not None"

2010-08-06 Thread Jean-Michel Pichavant
Steven D'Aprano wrote: On Thu, 05 Aug 2010 12:07:53 -0400, wheres pythonmonks wrote: P.S. Sorry for the top-post -- is there a way to not do top posts from gmail? I haven't used usenet since tin. Er, surely you can just move the cursor before you start typing??? CTRL+END will b

Re: easy question on parsing python: "is not None"

2010-08-06 Thread Richard D. Moores
On Fri, Aug 6, 2010 at 01:32, Bruno Desthuilliers wrote: > Richard D. Moores a écrit : >> >> On Thu, Aug 5, 2010 at 16:15, Rhodri James >> wrote: >>> >>> On Thu, 05 Aug 2010 17:07:53 +0100, wheres pythonmonks >>> wrote: >> >>> You're not testing for equivalence there, you're testing for identity

Re: easy question on parsing python: "is not None"

2010-08-06 Thread Bruno Desthuilliers
Richard D. Moores a écrit : On Thu, Aug 5, 2010 at 16:15, Rhodri James wrote: On Thu, 05 Aug 2010 17:07:53 +0100, wheres pythonmonks wrote: You're not testing for equivalence there, you're testing for identity. "is" and "is not" test whether the two objects concerned are (or are not) the s

Re: easy question on parsing python: "is not None"

2010-08-06 Thread Bruno Desthuilliers
Roald de Vries a écrit : 'not None' first casts None to a bool, and then applies 'not', so 'x is not None' means 'x is True'. Obviously plain wrong : Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) [GCC 4.3.3] on linux2 Type "help", "copyright", "credits" or "license" for more informat

Re: easy question on parsing python: "is not None"

2010-08-06 Thread Richard D. Moores
On Thu, Aug 5, 2010 at 16:15, Rhodri James wrote: > On Thu, 05 Aug 2010 17:07:53 +0100, wheres pythonmonks > wrote: > You're not testing for equivalence there, you're testing for identity.  "is" > and "is not" test whether the two objects concerned are (or are not) the > same object.  Two object

Re: easy question on parsing python: "is not None"

2010-08-05 Thread Steven D'Aprano
On Thu, 05 Aug 2010 12:07:53 -0400, wheres pythonmonks wrote: > P.S. Sorry for the top-post -- is there a way to not do top posts from > gmail? I haven't used usenet since tin. Er, surely you can just move the cursor before you start typing??? -- Steven -- http://mail.python.org/mailman/lis

Re: easy question on parsing python: "is not None"

2010-08-05 Thread Rhodri James
On Thu, 05 Aug 2010 17:07:53 +0100, wheres pythonmonks wrote: Well, I am not convinced of the equivalence of not None and true: not None True 3 is True; False 3 is not None True You're not testing for equivalence there, you're testing for identity. "is" and "is not" test whether

Re: easy question on parsing python: "is not None"

2010-08-05 Thread Benjamin Kaplan
On Thu, Aug 5, 2010 at 9:07 AM, wheres pythonmonks wrote: > Well, I am not convinced of the equivalence of not None and true: > not None > True 3 is True; > False 3 is not None > True > > P.S. Sorry for the top-post -- is there a way to not do top posts from > gmail?  I haven't

Re: easy question on parsing python: "is not None"

2010-08-05 Thread Ethan Furman
Roald de Vries wrote: On Aug 5, 2010, at 5:42 PM, wheres pythonmonks wrote: How does "x is not None" make any sense? "not x is None" does make sense. I can only surmise that in this context (preceding is) "not" is not a unary right-associative operator, therefore: x is not None === IS_NOTEQ(

Re: easy question on parsing python: "is not None"

2010-08-05 Thread Dave Angel
Roald de Vries wrote: On Aug 5, 2010, at 5:42 PM, wheres pythonmonks wrote: How does "x is not None" make any sense? "not x is None" does make sense. I can only surmise that in this context (preceding is) "not" is not a unary right-associative operator, therefore: x is not None === IS_NOTEQ(

Re: easy question on parsing python: "is not None"

2010-08-05 Thread Roald de Vries
On Aug 5, 2010, at 6:11 PM, Chris Rebert wrote: On Thu, Aug 5, 2010 at 8:56 AM, Roald de Vries wrote: On Aug 5, 2010, at 5:42 PM, wheres pythonmonks wrote: How does "x is not None" make any sense? "not x is None" does make sense. I can only surmise that in this context (preceding is) "not

Re: easy question on parsing python: "is not None"

2010-08-05 Thread Chris Rebert
On Thu, Aug 5, 2010 at 8:42 AM, wheres pythonmonks wrote: > How does "x is not None" make any sense?  "not x is None" does make sense. > > I can only surmise that in this context (preceding is) "not" is not a > unary right-associative operator, therefore: > > x is not None === IS_NOTEQ(X, None) >

Re: easy question on parsing python: "is not None"

2010-08-05 Thread Chris Rebert
On Thu, Aug 5, 2010 at 8:56 AM, Roald de Vries wrote: > On Aug 5, 2010, at 5:42 PM, wheres pythonmonks wrote: >> How does "x is not None" make any sense?  "not x is None" does make sense. >> >> I can only surmise that in this context (preceding is) "not" is not a >> unary right-associative operato

Re: easy question on parsing python: "is not None"

2010-08-05 Thread Carey Tilden
On Thu, Aug 5, 2010 at 8:42 AM, wheres pythonmonks wrote: > How does "x is not None" make any sense?  "not x is None" does make sense. > > I can only surmise that in this context (preceding is) "not" is not a > unary right-associative operator, therefore: > > x is not None === IS_NOTEQ(X, None) >

Re: easy question on parsing python: "is not None"

2010-08-05 Thread wheres pythonmonks
Well, I am not convinced of the equivalence of not None and true: >>> not None True >>> 3 is True; False >>> 3 is not None True >>> P.S. Sorry for the top-post -- is there a way to not do top posts from gmail? I haven't used usenet since tin. On Thu, Aug 5, 2010 at 11:56 AM, Roald de Vries wro

Re: easy question on parsing python: "is not None"

2010-08-05 Thread Ben Finney
wheres pythonmonks writes: > How does "x is not None" make any sense? In two ways: partly from the fact that Python syntax is preferentially designed to be reasonably readable to a native English reader; and partly because it makes for more obvious semantics. ‘is not’ is a single operator which

Re: easy question on parsing python: "is not None"

2010-08-05 Thread Jean-Michel Pichavant
wheres pythonmonks wrote: How does "x is not None" make any sense? "not x is None" does make sense. I can only surmise that in this context (preceding is) "not" is not a unary right-associative operator, therefore: x is not None === IS_NOTEQ(X, None) Beside "not in" which seems to work simila

Re: easy question on parsing python: "is not None"

2010-08-05 Thread Roald de Vries
On Aug 5, 2010, at 5:42 PM, wheres pythonmonks wrote: How does "x is not None" make any sense? "not x is None" does make sense. I can only surmise that in this context (preceding is) "not" is not a unary right-associative operator, therefore: x is not None === IS_NOTEQ(X, None) Beside "not

easy question on parsing python: "is not None"

2010-08-05 Thread wheres pythonmonks
How does "x is not None" make any sense? "not x is None" does make sense. I can only surmise that in this context (preceding is) "not" is not a unary right-associative operator, therefore: x is not None === IS_NOTEQ(X, None) Beside "not in" which seems to work similarly, is there other syntacti