Re: Surprise using the 'is' operator

2006-09-27 Thread tobiah
>> I don't pretend to understand the reasons for all of this, >> but if it is possible to use the same integer object whenever >> it is referenced, then why should there be a limit on range? > > Preallocating all the 4 billion 4-byte ints would overfill the memory of > most machines ;-) Sure, I

Re: Surprise using the 'is' operator

2006-09-27 Thread Georg Brandl
Terry Reedy wrote: > "Georg Brandl" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >> tobiah wrote: >>> Suppose I fill an list with 100 million random integers in the range >>> of 1 - 65535. Wouldn't I save much memory if all of the ocurrances >>> of '12345' pointed to the same int

Re: Surprise using the 'is' operator

2006-09-27 Thread Terry Reedy
"Georg Brandl" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > tobiah wrote: >> Suppose I fill an list with 100 million random integers in the range >> of 1 - 65535. Wouldn't I save much memory if all of the ocurrances >> of '12345' pointed to the same integer object? Why should m

Re: Surprise using the 'is' operator

2006-09-27 Thread Terry Reedy
"tobiah" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > wesley chun wrote: >>> "Terry Reedy" <[EMAIL PROTECTED]> wrote: >>> > as a side note, the ints that are cached (for current versions of >>> > Python) are in range(-1, 100)... is this documented somewhere? >>> Not true for at l

Re: Surprise using the 'is' operator

2006-09-27 Thread Steve Holden
tobiah wrote: > Simon Brunning wrote: > >>On 9/27/06, tobiah <[EMAIL PROTECTED]> wrote: >> >>>Suppose I fill an list with 100 million random integers in the range >>>of 1 - 65535. Wouldn't I save much memory if all of the ocurrances >>>of '12345' pointed to the same integer object? Why should mo

Re: Surprise using the 'is' operator

2006-09-27 Thread Duncan Booth
Georg Brandl <[EMAIL PROTECTED]> wrote: >> Suppose I fill an list with 100 million random integers in the range >> of 1 - 65535. Wouldn't I save much memory if all of the ocurrances >> of '12345' pointed to the same integer object? Why should more be >> made, when they all do the same thing, and

Re: Surprise using the 'is' operator

2006-09-27 Thread Georg Brandl
tobiah wrote: >>> Suppose I fill an list with 100 million random integers in the range >>> of 1 - 65535. Wouldn't I save much memory if all of the ocurrances >>> of '12345' pointed to the same integer object? Why should more be made, >>> when they all do the same thing, and are not subject to cha

Re: Surprise using the 'is' operator

2006-09-27 Thread tobiah
>> Suppose I fill an list with 100 million random integers in the range >> of 1 - 65535. Wouldn't I save much memory if all of the ocurrances >> of '12345' pointed to the same integer object? Why should more be made, >> when they all do the same thing, and are not subject to change? > > Because

Re: Surprise using the 'is' operator

2006-09-27 Thread tobiah
Simon Brunning wrote: > On 9/27/06, tobiah <[EMAIL PROTECTED]> wrote: >> Suppose I fill an list with 100 million random integers in the range >> of 1 - 65535. Wouldn't I save much memory if all of the ocurrances >> of '12345' pointed to the same integer object? Why should more be made, >> when th

Re: Surprise using the 'is' operator

2006-09-27 Thread Georg Brandl
tobiah wrote: > wesley chun wrote: >>> "Terry Reedy" <[EMAIL PROTECTED]> wrote: >>> > as a side note, the ints that are cached (for current versions of >>> > Python) are in range(-1, 100)... is this documented somewhere? >>> Not true for at least 2.4 and 2.5. The cached range has expanded >> >> o

Re: Surprise using the 'is' operator

2006-09-27 Thread Simon Brunning
On 9/27/06, tobiah <[EMAIL PROTECTED]> wrote: > Suppose I fill an list with 100 million random integers in the range > of 1 - 65535. Wouldn't I save much memory if all of the ocurrances > of '12345' pointed to the same integer object? Why should more be made, > when they all do the same thing, an

Re: Surprise using the 'is' operator

2006-09-27 Thread tobiah
wesley chun wrote: >> "Terry Reedy" <[EMAIL PROTECTED]> wrote: >> > as a side note, the ints that are cached (for current versions of >> > Python) are in range(-1, 100)... is this documented somewhere? >> Not true for at least 2.4 and 2.5. The cached range has expanded > > oops, apologies to all.

Re: Surprise using the 'is' operator

2006-09-26 Thread wesley chun
> "Terry Reedy" <[EMAIL PROTECTED]> wrote: > > as a side note, the ints that are cached (for current versions of > > Python) are in range(-1, 100)... is this documented somewhere? > Not true for at least 2.4 and 2.5. The cached range has expanded oops, apologies to all... it really *is* subject t

Re: Surprise using the 'is' operator

2006-09-26 Thread Terry Reedy
"wesley chun" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > as a side note, the ints that are cached (for current versions of > Python) are in range(-1, 100)... is this documented somewhere? Not true for at least 2.4 and 2.5. The cached range has expanded > i know it's subject

Re: Surprise using the 'is' operator

2006-09-26 Thread skip
Wesley> as a side note, the ints that are cached (for current versions Wesley> of Python) are in range(-1, 100)... is this documented Wesley> somewhere? Other than the code, probably not. Since it's an implementation optimization, I see no particular reason that it should be document

Re: Surprise using the 'is' operator

2006-09-26 Thread wesley chun
as a side note, the ints that are cached (for current versions of Python) are in range(-1, 100)... is this documented somewhere? i know it's subject to change. and as already mentioned, you probably wouldn't use "is" this way in real code... i know you are just reinforcing your learning of the dif

Re: Surprise using the 'is' operator

2006-09-26 Thread John Roth
Antoon Pardon wrote: > > I find this a bit oddly worded. Now the "may always reuse" phrase > suggests this is not an obligation and I can certainly understand > that in the case of integers. But when you enumerate examples you > include None and Booleans, creating the suggestion these don't > have

Re: Surprise using the 'is' operator

2006-09-26 Thread Antoon Pardon
On 2006-09-26, John Roth <[EMAIL PROTECTED]> wrote: > > Antoon Pardon wrote: >> >> I find this a bit oddly worded. Now the "may always reuse" phrase >> suggests this is not an obligation and I can certainly understand >> that in the case of integers. But when you enumerate examples you >> include N

Re: Surprise using the 'is' operator

2006-09-26 Thread Ben Finney
"codefire" <[EMAIL PROTECTED]> writes: > I was just trying to check if objects were the same (object), didn't > know Integers were a special case. They're not. The Python runtime environment can do whatever it likes underneath the hood; the language gives no promises about any relationship betwee

Re: Surprise using the 'is' operator

2006-09-26 Thread codefire
Thanks for that Fredrik, that's clear. That's actually a pretty nice feature as it's nicely optimised. >>> a = 10 >>> c = 10 >>> a is c True >>> c = c +1 >>> a is c False >>> Cheers, Tony -- http://mail.python.org/mailman/listinfo/python-list

Re: Surprise using the 'is' operator

2006-09-26 Thread codefire
Haha! OK thanks guys. I was just trying to check if objects were the same (object), didn't know Integers were a special case. Thanks, Tony -- http://mail.python.org/mailman/listinfo/python-list

Re: Surprise using the 'is' operator

2006-09-26 Thread Antoon Pardon
On 2006-09-26, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > codefire wrote: > >> I was just trying to check if objects were the same (object), didn't >> know Integers were a special case. > > they're not, really; "is" works the same way for all objects. > > when you ask for a new immutable object, a

Re: Surprise using the 'is' operator

2006-09-26 Thread Christophe
codefire a écrit : > Haha! > > OK thanks guys. > > I was just trying to check if objects were the same (object), didn't > know Integers were a special case. They are not a special case so much. It's just that "is" is extremly unreliable unless you're the one who created the objects. In the case

Re: Surprise using the 'is' operator

2006-09-26 Thread Fredrik Lundh
codefire wrote: > I was just trying to check if objects were the same (object), didn't > know Integers were a special case. they're not, really; "is" works the same way for all objects. when you ask for a new immutable object, a Python implementation may always reuse an existing object, if it w

Re: Surprise using the 'is' operator

2006-09-26 Thread Christophe
codefire a écrit : > I thought the 'is' operator was used to identify identical objects, > whereas the '==' operator checked equality. Well, I got a surprise > here: > > IDLE 1.1.3 a = 10 b = a a is b > True a == b > True c = 10 a == c > True a is c > True > > I

Re: Surprise using the 'is' operator

2006-09-26 Thread Diez B. Roggisch
codefire wrote: > I thought the 'is' operator was used to identify identical objects, > whereas the '==' operator checked equality. Well, I got a surprise > here: > > IDLE 1.1.3 a = 10 b = a a is b > True a == b > True c = 10 a == c > True a is c > True >

Surprise using the 'is' operator

2006-09-26 Thread codefire
I thought the 'is' operator was used to identify identical objects, whereas the '==' operator checked equality. Well, I got a surprise here: IDLE 1.1.3 >>> a = 10 >>> b = a >>> a is b True >>> a == b True >>> c = 10 >>> a == c True >>> a is c True >>> I was NOT expecting the last statement to ret