Re: python string comparison oddity

2008-06-19 Thread Hrvoje Niksic
Faheem Mitha <[EMAIL PROTECTED]> writes: > Yes, but why is '-' and 'foo' cached, and not '--'? Do you know what > the basis of the choice is? Caches such as intern dictionary/set and one-character cache are specific to the implementation (and also to its version version, etc.). In this case '-'

Re: python string comparison oddity

2008-06-19 Thread Duncan Booth
Faheem Mitha <[EMAIL PROTECTED]> wrote: >>> In [1]: a = '--' >>> >>> In [2]: a is '--' >>> Out[2]: False >>> >>> In [4]: a = '-' >>> >>> In [5]: a is '-' >>> Out[5]: True >>> >>> In [6]: a = 'foo' >>> >>> In [7]: a is 'foo' >>> Out[7]: True >> >> Yes, this happens because of small objects caching.

Re: python string comparison oddity

2008-06-19 Thread Lie
On Jun 19, 5:13 am, Faheem Mitha <[EMAIL PROTECTED]> wrote: > On Wed, 18 Jun 2008 12:57:44 -0700 (PDT), Lie <[EMAIL PROTECTED]> wrote: > > On Jun 19, 2:26 am, Faheem Mitha <[EMAIL PROTECTED]> wrote: > >> Hi everybody, > > >> I was wondering if anyone can explain this. My understanding is that 'is'

Re: python string comparison oddity

2008-06-18 Thread Robert Kern
Faheem Mitha wrote: On Wed, 18 Jun 2008 12:57:44 -0700 (PDT), Lie <[EMAIL PROTECTED]> wrote: On Jun 19, 2:26 am, Faheem Mitha <[EMAIL PROTECTED]> wrote: Hi everybody, I was wondering if anyone can explain this. My understanding is that 'is' checks if the object is the same. However, in that ca

Re: python string comparison oddity

2008-06-18 Thread Faheem Mitha
On Wed, 18 Jun 2008 12:57:44 -0700 (PDT), Lie <[EMAIL PROTECTED]> wrote: > On Jun 19, 2:26 am, Faheem Mitha <[EMAIL PROTECTED]> wrote: >> Hi everybody, >> >> I was wondering if anyone can explain this. My understanding is that 'is' >> checks if the object is the same. However, in that case, why thi

Re: python string comparison oddity

2008-06-18 Thread Lie
On Jun 19, 2:26 am, Faheem Mitha <[EMAIL PROTECTED]> wrote: > Hi everybody, > > I was wondering if anyone can explain this. My understanding is that 'is' > checks if the object is the same. However, in that case, why this > inconsistency for short strings? I would expect a 'False' for all three > c

python string comparison oddity

2008-06-18 Thread Faheem Mitha
Hi everybody, I was wondering if anyone can explain this. My understanding is that 'is' checks if the object is the same. However, in that case, why this inconsistency for short strings? I would expect a 'False' for all three comparisons. This is reproducible across two different machines, so