Re: Legitimate use of the is comparison operator?

2006-06-19 Thread David Isaac
(I was using *small* integers). Fredrik Lundh [EMAIL PROTECTED] wrote: small integers is what the phrase small integers in the small integers and small integers parts of my reply referred too, of course. But aren't *small* integers likely to be smaller than small integers? Alan Isaac --

Legitimate use of the is comparison operator?

2006-06-17 Thread Mike Duffy
I just recently realized that the comparison operator is actually works for comparing numeric values. Now, I know that its intended use is for testing object identity, but I have used it for a few other things, such as type checking, and I was just wondering whether or not it is considered bad

Re: Legitimate use of the is comparison operator?

2006-06-17 Thread Jean-Paul Calderone
On 17 Jun 2006 00:49:51 -0700, Mike Duffy [EMAIL PROTECTED] wrote: I just recently realized that the comparison operator is actually works for comparing numeric values. Now, I know that its intended use is for testing object identity, but I have used it for a few other things, such as type

Re: Legitimate use of the is comparison operator?

2006-06-17 Thread Fredrik Lundh
Mike Duffy wrote: I just recently realized that the comparison operator is actually works for comparing numeric values. except that it doesn't work. Now, I know that its intended use is for testing object identity, but I have used it for a few other things, such as type checking, and I

Re: Legitimate use of the is comparison operator?

2006-06-17 Thread Gary Herron
Jean-Paul Calderone wrote: On 17 Jun 2006 00:49:51 -0700, Mike Duffy [EMAIL PROTECTED] wrote: I just recently realized that the comparison operator is actually works for comparing numeric values. Now, I know that its intended use is for testing object identity, but I have used it for a few

Re: Legitimate use of the is comparison operator?

2006-06-17 Thread Mike Duffy
Fredrik Lundh wrote: except that it doesn't work. writing broken code is never a good practice. With all due respect, for some reason it seems to work on my machine. Because I certainly agree with you about writing broken code. Python 2.4.2 (#1, Jan 17 2006, 16:52:02) [GCC 4.0.0 20041026

Re: Legitimate use of the is comparison operator?

2006-06-17 Thread Fredrik Lundh
Mike Duffy wrote: writing broken code is never a good practice. With all due respect, for some reason it seems to work on my machine. if you always work with 5-item sequences, you don't need the test at all. /F -- http://mail.python.org/mailman/listinfo/python-list

Re: Legitimate use of the is comparison operator?

2006-06-17 Thread Mike Duffy
Gary Herron wrote: 100 is (99+1) False 2 is (1+1) True 100 is 100 True This is highly implementation dependent. The current (C) implementation of Python has a cache for small integers, so the attempt to compare values with is works for some small integers, and fails for some large

Re: Legitimate use of the is comparison operator?

2006-06-17 Thread Fredrik Lundh
Mike Duffy wrote: Ahh, thank you. That explains why Fredrick's and Jean-Paul's example did not work, but mine did (I was using *small* integers). small integers is what the phrase small integers in the small integers and small integers parts of my reply referred too, of course. /F --

Re: Legitimate use of the is comparison operator?

2006-06-17 Thread bruno at modulix
Mike Duffy wrote: I just recently realized that the comparison operator is actually works for comparing numeric values. It's only an implementation detail of CPython (and is only true for small integers - you'll find the limit in the CPython source code), not part of the language