Re: String Identity Test

2009-03-05 Thread Bruno Desthuilliers
Hendrik van Rooyen a écrit : S Arrowsmith si...intbox.UUCP wrote: Small integers get a similar treatment: a = 256 b = 256 a is b True a = 257 b = 257 a is b False This is weird - I would have thought that the limit of small would be at 255 - the biggest number to fit in a byte. 256

Re: String Identity Test

2009-03-05 Thread Bruno Desthuilliers
Avetis KAZARIAN a écrit : Well, it's not about curiosity, it's more about performance. Steve Holden wrote: (snip) So, don't try to translate concepts from one language to another. I'll try ;] Also and FWIW: 1/ Python has some very handy tools when it comes to perfs - like a couple

Re: String Identity Test

2009-03-05 Thread Terry Reedy
Hendrik van Rooyen wrote: S Arrowsmith si...intbox.UUCP wrote: Small integers get a similar treatment: a = 256 b = 256 a is b True a = 257 b = 257 a is b False This is weird - I would have thought that the limit of small would be at 255 - the biggest number to fit in a byte. 256 takes

Re: String Identity Test

2009-03-05 Thread Terry Reedy
Terry Reedy wrote: Hendrik van Rooyen wrote: S Arrowsmith si...intbox.UUCP wrote: Small integers get a similar treatment: a = 256 b = 256 a is b True a = 257 b = 257 a is b False This is weird - I would have thought that the limit of small would be at 255 - the biggest number to fit in

Re: String Identity Test

2009-03-04 Thread Terry Reedy
Avetis KAZARIAN wrote: After reading the discussion about the same subject ( From: Thomas Moore jsfrank.c...@msa.hinet.net Date: Tue, 1 Nov 2005 21:45:56 +0800 ), I tried myself some tests with some confusing results (I'm a beginner with Python, I'm coming from PHP) For immutable objects,

Re: String Identity Test

2009-03-04 Thread Avetis KAZARIAN
Gary Herron wrote: The question now is: Why do you care? The properties of strings do not depend on the implementation's choice, so you shouldn't care because of programming considerations. Perhaps it's just a matter of curiosity on your part. Gary Herron Well, it's not about curiosity,

Re: String Identity Test

2009-03-04 Thread Tino Wildenhain
Avetis KAZARIAN wrote: Gary Herron wrote: The question now is: Why do you care? The properties of strings do not depend on the implementation's choice, so you shouldn't care because of programming considerations. Perhaps it's just a matter of curiosity on your part. Gary Herron Well,

Re: String Identity Test

2009-03-04 Thread Christian Heimes
Avetis KAZARIAN schrieb: Gary Herron wrote: The question now is: Why do you care? The properties of strings do not depend on the implementation's choice, so you shouldn't care because of programming considerations. Perhaps it's just a matter of curiosity on your part. Gary Herron

Re: String Identity Test

2009-03-04 Thread Avetis KAZARIAN
Everything's clear now. Thanks all (especially Christian and Tino) :] -- http://mail.python.org/mailman/listinfo/python-list

Re: String Identity Test

2009-03-04 Thread Peter Otten
Avetis KAZARIAN wrote: Gary Herron wrote: The question now is: Why do you care? The properties of strings do not depend on the implementation's choice, so you shouldn't care because of programming considerations. Perhaps it's just a matter of curiosity on your part. Gary Herron

Re: String Identity Test

2009-03-04 Thread Steve Holden
Avetis KAZARIAN wrote: Gary Herron wrote: The question now is: Why do you care? The properties of strings do not depend on the implementation's choice, so you shouldn't care because of programming considerations. Perhaps it's just a matter of curiosity on your part. Gary Herron Well,

Re: String Identity Test

2009-03-04 Thread Gabriel Genellina
En Wed, 04 Mar 2009 07:07:44 -0200, Avetis KAZARIAN aveti...@gmail.com escribió: Gary Herron wrote: The question now is: Why do you care? The properties of strings do not depend on the implementation's choice, so you shouldn't care because of programming considerations. Perhaps it's just

Re: String Identity Test

2009-03-04 Thread Avetis KAZARIAN
Steve Holden wrote: Does PHP really keep only one copy of every string? Not at all. I might have said something confusing if you understood that... So, don't try to translate concepts from one language to another. -- Gabriel Genellina I'll try ;] --

Re: String Identity Test

2009-03-04 Thread S Arrowsmith
Avetis KAZARIAN aveti...@gmail.com wrote: It seems that any strict ASCII alpha-numeric string is instantiated as an unique object, like a singleton ( a =3D x and b =3D x =3D a is b = ) and that any non strict ASCII alpha-numeric string is instantiated as a new object every time with a new id.

Re: String Identity Test

2009-03-04 Thread Hendrik van Rooyen
S Arrowsmith si...intbox.UUCP wrote: Small integers get a similar treatment: a = 256 b = 256 a is b True a = 257 b = 257 a is b False This is weird - I would have thought that the limit of small would be at 255 - the biggest number to fit in a byte. 256 takes two bytes, so it

String Identity Test

2009-03-03 Thread Avetis KAZARIAN
After reading the discussion about the same subject ( From: Thomas Moore jsfrank.c...@msa.hinet.net Date: Tue, 1 Nov 2005 21:45:56 +0800 ), I tried myself some tests with some confusing results (I'm a beginner with Python, I'm coming from PHP) # 1. Short alpha-numeric String without space a =

Re: String Identity Test

2009-03-03 Thread Gary Herron
Avetis KAZARIAN wrote: After reading the discussion about the same subject ( From: Thomas Moore jsfrank.c...@msa.hinet.net Date: Tue, 1 Nov 2005 21:45:56 +0800 ), I tried myself some tests with some confusing results (I'm a beginner with Python, I'm coming from PHP) # 1. Short alpha-numeric

Re: String Identity Test

2005-11-02 Thread Thomas Moore
Hi: Were you planning to write code that relied on id(x) being different for different but identical strings x or do you just try to understand what's going on? Just try to understand what's going on. Thanks All. -- http://mail.python.org/mailman/listinfo/python-list

Re: String Identity Test

2005-11-02 Thread Tim Roberts
Richard Brodie [EMAIL PROTECTED] wrote: Roy Smith [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] On the other hand, I can't imagine any reason why you would want to define such a class, PEP 754? My congratulations on a very subtle and somewhat multicultural joke... -- - Tim

String Identity Test

2005-11-01 Thread Thomas Moore
Hi: I am confused at string identity test: Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on win32 Type help, copyright, credits or license for more information. a=test b=test a is b True About identity, I think a is not b, but a is b returns True. Does that mean

Re: String Identity Test

2005-11-01 Thread Benji York
Thomas Moore wrote: I am confused at string identity test: a=test b=test a is b True About identity, I think a is not b, but a is b returns True. Does that mean equality and identity is the same thing for strings? Nope: a = 'te' + 'st' b = 'test' a is b False You're seeing

Re: String Identity Test

2005-11-01 Thread Fredrik Lundh
Thomas Moore wrote: I am confused at string identity test: Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on win32 Type help, copyright, credits or license for more information. a=test b=test a is b True About identity, I think a is not b, but a is b returns

Re: String Identity Test

2005-11-01 Thread Duncan Booth
Thomas Moore wrote: I am confused at string identity test: snip Does that mean equality and identity is the same thing for strings? Definitely not. What is actually happening is that certain string literals get folded together at compile time to refer to the same string constant, but you

Re: String Identity Test

2005-11-01 Thread Magnus Lycka
Thomas Moore wrote: a=test b=test a is b True About identity, I think a is not b, but a is b returns True. Does that mean equality and identity is the same thing for strings? Not exactly: a=this is also a string b=this is also a string a is b False It's the same with integers. Small

Re: String Identity Test

2005-11-01 Thread Roy Smith
Duncan Booth [EMAIL PROTECTED] wrote: If 'a!=b' then it will also be the case that 'a is not b' That's true for strings, and (as far as I know), all pre-defined types, but it's certainly possible to define a class which violates that. class isButNotEqual: def __ne__ (self, other):

Re: String Identity Test

2005-11-01 Thread Richard Brodie
Roy Smith [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] On the other hand, I can't imagine any reason why you would want to define such a class, PEP 754? -- http://mail.python.org/mailman/listinfo/python-list