[Python-Dev] Re: [spambayes-dev] RE: RE: [Spambayes] Question (orpossibly a bug report)

Tim Peters tim.one@comcast.net
Fri, 25 Jul 2003 11:37:50 -0400

[Scott David Daniels]
> I've been seeing a lot of "we'll have to use float(123)/100"
> messages floating around, and I'd like to point out there is an
> atof-able form for floating point numbers:
>            256.7654e-7  =  2567654e-11

Skip is right that this won't help.  At compile time, Python doesn't stuff
pieces of the source code into a .pyc file, it builds the float objects and
marshals them.  Here's temp.py:

def example():
    return 1e-1


>>> import temp
>>> file('temp.pyc', 'rb').read()

The substring


is the marshal typecode for a float, a byte saying the float string is in
the next 0x13 = 19 bytes, and then the 19-byte string "0.10000000000000001".
The source code's exponential notation didn't survive in the .pyc file.