Can a simple a==b 'hang' in and endless loop?
Dave Hansen
iddw at hotmail.com
Wed Jan 18 15:52:27 EST 2006
On Wed, 18 Jan 2006 17:03:23 +0100 in comp.lang.python, Claudio Grondi
<claudio.grondi at freenet.de> wrote:
[...]
>
> >>> a = 1L
> >>> b = 1L
> >>> a is b
>False
>
>Python fails to reuse the long integer object. It would be interesting
>to know why, because it seems to be strange, that in case of integers it
>does (but not always and I don't know actually when it happens and what
>it depends upon). Reusing long integers would make much more sense than
>reusing plain integers when considering memory spent on storage.
>Hmmm...
I suspect it's a matter of practicality beating purity. Consider
a = 1L
b = 10L
... much code ...
c = b/5
... more code ...
d = c * 3
... still more code ...
e = a * 6
... and now the question ...
print d is e
Do you really want the interpreter, on each long integer assignment
operation (5 in the above example), to find all the long integer
objects, perform a comparison, and re-use objects that compare equal?
Or would you rather the "is" operator alias "==" for longs?
Are either of these options really useful?
Regards,
-=Dave
--
Change is inevitable, progress is not.
More information about the Python-list
mailing list