[Python-Dev] Caching float(0.0)

Nick Craig-Wood nick at craig-wood.com
Sun Oct 1 11:38:46 CEST 2006


On Fri, Sep 29, 2006 at 12:03:03PM -0700, Guido van Rossum wrote:
> I see some confusion in this thread.
> 
> If a *LITERAL* 0.0 (or any other float literal) is used, you only get
> one object, no matter how many times it is used.

For some reason that doesn't happen in the interpreter which has been
confusing the issue slightly...

$ python2.5
Python 2.5c1 (r25c1:51305, Aug 19 2006, 18:23:29)
[GCC 4.1.2 20060814 (prerelease) (Debian 4.1.1-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> a=0.0
>>> b=0.0
>>> id(a), id(b)
(134737756, 134737772)
>>>

$ python2.5 -c 'a=0.0; b=0.0; print id(a),id(b)'
134737796 134737796

> But if the result of a *COMPUTATION* returns 0.0, you get a new object
> for each such result. If you have 70 MB worth of zeros, that's clearly
> computation results, not literals.

In my application I'm receiving all the zeros from a server over TCP
as ASCII and these are being float()ed in python.

-- 
Nick Craig-Wood <nick at craig-wood.com> -- http://www.craig-wood.com/nick


More information about the Python-Dev mailing list