[Python-Dev] Caching float(0.0)
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...
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.
>>> id(a), id(b)
$ python2.5 -c 'a=0.0; b=0.0; print id(a),id(b)'
> 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