Re: Puzzled by "is"

2007-08-12 Thread Dick Moores
At 09:59 AM 8/12/2007, Steve Holden wrote: >Dick Moores wrote: > > At 08:23 AM 8/12/2007, Steve Holden wrote: > >> Dick Moores wrote: > >>> So would a programmer EVER use "is" in a script? > >> Sure. For example, the canonical test for None uses > >> > >> x is None > >> > >> because there is o

Re: Puzzled by "is"

2007-08-12 Thread Steve Holden
Dick Moores wrote: > At 08:23 AM 8/12/2007, Steve Holden wrote: >> Dick Moores wrote: >>> So would a programmer EVER use "is" in a script? >> Sure. For example, the canonical test for None uses >> >> x is None >> >> because there is only ever one instance of type Nonetype, so it's the >> faste

Re: Puzzled by "is"

2007-08-12 Thread Dick Moores
At 08:23 AM 8/12/2007, Steve Holden wrote: >Dick Moores wrote: > > So would a programmer EVER use "is" in a script? > >Sure. For example, the canonical test for None uses > > x is None > >because there is only ever one instance of type Nonetype, so it's the >fastest test. Generally speaking yo

Re: Puzzled by "is"

2007-08-12 Thread Steve Holden
Dick Moores wrote: > On 8/12/07, *Ben Finney* <[EMAIL PROTECTED] > > wrote: > > Dick Moores <[EMAIL PROTECTED] > writes: > > > At 06:13 PM 8/9/2007, Ben Finney wrote: > > >it's entirely left to the language implementation which >

Re: Puzzled by "is"

2007-08-12 Thread Dick Moores
On 8/12/07, Ben Finney <[EMAIL PROTECTED]> wrote: > > Dick Moores <[EMAIL PROTECTED]> writes: > > > At 06:13 PM 8/9/2007, Ben Finney wrote: > > >it's entirely left to the language implementation which > > >optimisation trade-offs to make, and the language user (that's you > > >and I) should *not* e

Re: Puzzled by "is"

2007-08-12 Thread Ben Finney
Dick Moores <[EMAIL PROTECTED]> writes: > At 06:13 PM 8/9/2007, Ben Finney wrote: > >it's entirely left to the language implementation which > >optimisation trade-offs to make, and the language user (that's you > >and I) should *not* expect any particular behaviour to hold between > >different imp

Re: Puzzled by "is"

2007-08-10 Thread Trent Mick
Dick Moores wrote: > At 06:13 PM 8/9/2007, Ben Finney wrote: >> It's important to also realise that the language is *deliberately* >> non-committal on whether any given value will have this behaviour; >> that is, it's entirely left to the language implementation which >> optimisation trade-offs to

Re: Puzzled by "is"

2007-08-10 Thread Marc 'BlackJack' Rintsch
On Fri, 10 Aug 2007 10:57:22 -0700, Dick Moores wrote: > At 06:13 PM 8/9/2007, Ben Finney wrote: >>Others have already said that it's an implementation optimisation, >>which seems to partly answer your question. >> >>It's important to also realise that the language is *deliberately* >>non-committa

Re: Puzzled by "is"

2007-08-10 Thread Dick Moores
At 06:13 PM 8/9/2007, Ben Finney wrote: >Content-Transfer-Encoding: base64Grzegorz >Słodkowicz <[EMAIL PROTECTED] [EMAIL PROTECTED] >theorisation but I'd rather expect the interpreter > > simply not to create a second tuple while there already is an > > identical one. > >Others have already sai

Re: Puzzled by "is"

2007-08-09 Thread Paul Rudin
John K Masters <[EMAIL PROTECTED]> writes: > > OK fiddling around with this and reading the docs I tried:- > a = 'qq' #10 q's > b = 'qq' #10 q's > a is b > true > c = 'q' * 10 > c > 'qq' #10 q's > d = 'q' * 10 > d > 'qq' #10 q's > c is d > false > > So from what I'v

Re: Puzzled by "is"

2007-08-09 Thread Erik Max Francis
Ben Finney wrote: > It's important to also realise that the language is *deliberately* > non-committal on whether any given value will have this behaviour; > that is, it's entirely left to the language implementation which > optimisation trade-offs to make, and the language user (that's you and >

Re: Puzzled by "is"

2007-08-09 Thread Ben Finney
Grzegorz Słodkowicz <[EMAIL PROTECTED]> writes: > That's just theorisation but I'd rather expect the interpreter > simply not to create a second tuple while there already is an > identical one. Others have already said that it's an implementation optimisation, which seems to partly answer your qu

Re: Puzzled by "is"

2007-08-09 Thread Hrvoje Niksic
Grzegorz Słodkowicz <[EMAIL PROTECTED]> writes: >> Seriously, it's just an optimization by the implementers. There is >> no need for more than one empty tuple, since tuples can never be >> modified once created. >> >> But they decided not to create (1, ) in advance. They probably knew >> that hard

Re: Puzzled by "is"

2007-08-09 Thread Steve Holden
Grzegorz Słodkowicz wrote: >> Why? Because. >> >> Seriously, it's just an optimization by the implementers. There is no >> need for more than one empty tuple, since tuples can never be modified >> once created. >> >> But they decided not to create (1, ) in advance. They probably knew that >> har

Re: Puzzled by "is"

2007-08-09 Thread Erik Max Francis
Grzegorz Słodkowicz wrote: > That's just theorisation but I'd rather expect the interpreter simply > not to create a second tuple while there already is an identical one. > This could save some memory if the tuple was large (Although by the same > token comparison of large tuples can be expensi

Re: Puzzled by "is"

2007-08-09 Thread Erik Max Francis
John K Masters wrote: > OK fiddling around with this and reading the docs I tried:- > a = 'qq' #10 q's > b = 'qq' #10 q's > a is b > true > c = 'q' * 10 > c > 'qq' #10 q's > d = 'q' * 10 > d > 'qq' #10 q's > c is d > false > > So from what I've read "==" tests for

Re: Puzzled by "is"

2007-08-09 Thread Grzegorz Słodkowicz
> > Why? Because. > > Seriously, it's just an optimization by the implementers. There is no > need for more than one empty tuple, since tuples can never be modified > once created. > > But they decided not to create (1, ) in advance. They probably knew that > hardly anybody would want to create

Re: Puzzled by "is"

2007-08-09 Thread Steve Holden
[EMAIL PROTECTED] wrote: [...] > > Steve, > > I thought you'd probably weigh in on this esoteric matter. Very > illuminating, as usual. > Thank you! regards Steve -- Steve Holden+1 571 484 6266 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb

Re: Puzzled by "is"

2007-08-09 Thread Neil Cerutti
On 2007-08-09, John K Masters <[EMAIL PROTECTED]> wrote: > On 15:53 Thu 09 Aug , Steve Holden wrote: >> Dick Moores wrote: >> > At 10:46 AM 8/9/2007, Bill Scherer wrote: >> >> Dick Moores wrote: >> [...] >> >> There is only one empty tuple. >> >> Does that clear it up for you? >> > >> > But is

Re: Puzzled by "is"

2007-08-09 Thread kyosohma
On Aug 9, 2:53 pm, Steve Holden <[EMAIL PROTECTED]> wrote: > Dick Moores wrote: > > At 10:46 AM 8/9/2007, Bill Scherer wrote: > >> Dick Moores wrote: > [...] > >> There is only one empty tuple. > >> Does that clear it up for you? > > > But isn't that the same as saying, "That's just the reality of

Re: Puzzled by "is"

2007-08-09 Thread John K Masters
On 15:53 Thu 09 Aug , Steve Holden wrote: > Dick Moores wrote: > > At 10:46 AM 8/9/2007, Bill Scherer wrote: > >> Dick Moores wrote: > [...] > >> There is only one empty tuple. > >> Does that clear it up for you? > > > > But isn't that the same as saying, "That's just the reality of > > Pytho

Re: Puzzled by "is"

2007-08-09 Thread Steve Holden
Dick Moores wrote: > At 10:46 AM 8/9/2007, Bill Scherer wrote: >> Dick Moores wrote: [...] >> There is only one empty tuple. >> Does that clear it up for you? > > But isn't that the same as saying, "That's just the reality of > Python; it is what it is."? I want to know why there is only one > e

Re: Puzzled by "is"

2007-08-09 Thread Dick Moores
At 10:46 AM 8/9/2007, Bill Scherer wrote: >Dick Moores wrote: > > >>> () is () > > True > > >>> (1,) is (1,) > > False > > > > Why? > > > > >>> a = () > >>> b = () > >>> c = (1,) > >>> d = (1,) > >>> a is b >True > >>> c is d >False > >>> id(a) >3086553132 > >>> id(b) >3086553132 > >>> id(c) >308

Re: Puzzled by "is"

2007-08-09 Thread Jay Loden
Jay Loden wrote: > Dick Moores wrote: >> >>> () is () >> True >> >>> (1,) is (1,) >> False >> >> Why? >> >> Thanks, >> >> Dick Moores > >From the docs for 'is': The operators is and is not test for object identity: x is y is true if and only if x and y are the same object. x is not y yi

Re: Puzzled by "is"

2007-08-09 Thread Neil Cerutti
On 2007-08-09, Dick Moores <[EMAIL PROTECTED]> wrote: > >>> () is () > True > >>> (1,) is (1,) > False > > Why? >From _Python Reference Manual_: 5.2.4 List displays: An empty pair of parentheses yields an empty tuple object. Since tuples are immutable, the rules for literals apply (i.e., tw

Re: Puzzled by "is"

2007-08-09 Thread Bill Scherer
Dick Moores wrote: > >>> () is () > True > >>> (1,) is (1,) > False > > Why? > >>> a = () >>> b = () >>> c = (1,) >>> d = (1,) >>> a is b True >>> c is d False >>> id(a) 3086553132 >>> id(b) 3086553132 >>> id(c) 3086411340 >>> id(d) 3086390892 There is only one empty tuple. Does that clear

Re: Puzzled by "is"

2007-08-09 Thread Jay Loden
Dick Moores wrote: > >>> () is () > True > >>> (1,) is (1,) > False > > Why? > > Thanks, > > Dick Moores >From the docs for 'is': -- http://mail.python.org/mailman/listinfo/python-list

Puzzled by "is"

2007-08-09 Thread Dick Moores
>>> () is () True >>> (1,) is (1,) False Why? Thanks, Dick Moores -- http://mail.python.org/mailman/listinfo/python-list