Variables different between .py and .pyc

Rainer Deyke root at rainerdeyke.com
Mon May 7 18:21:17 EDT 2001


"Scott Ransom" <ransom at cfa.harvard.edu> wrote in message
news:3AF70509.DCBB4086 at cfa.harvard.edu...
> Here is a simple module (vars.py):
>
> PI    = 3.14159265358979324
> TWOPI = 6.28318530717958648
>
> When I import this and check the variable values here is what I get:
>
> >>> import vars
> >>> vars.PI, vars.TWOPI
> (3.1415926535897931, 6.2831853071795862)
>
> All is well, so far.  Now, if I try again (and this time the interpreter
> loads from the newly created vars.pyc file):
>
> >>> import vars
> >>> vars.PI, vars.TWOPI
> (3.1415926535900001, 6.2831853071800001)
>
> My variables are truncated at ~12 decimal points of precision.
>
> Any idea why this is happening?

Because floating points are evil.  Alternately, because the marshalling
mechanism (which is used to create .pyc files) does not store floating point
number at full precision.


--
Rainer Deyke (root at rainerdeyke.com)
Shareware computer games           -           http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor





More information about the Python-list mailing list