Variables different between .py and .pyc
Scott Ransom
ransom at cfa.harvard.edu
Mon May 7 16:26:49 EDT 2001
Hello,
I'm running Python 2.0 on Linux and seem to have found a strange problem
when importing floating point variables defined in modules. I have not
tried this in Python 2.1 so I don't know if the problem exists there as
well.
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:
presto:~$ python
Python 2.0 (#6, Nov 16 2000, 12:32:08)
[GCC 2.95.2 20000220 (Debian GNU/Linux)] on linux2
Type "copyright", "credits" or "license" for more information.
>>> 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):
presto:~$ python
Python 2.0 (#6, Nov 16 2000, 12:32:08)
[GCC 2.95.2 20000220 (Debian GNU/Linux)] on linux2
Type "copyright", "credits" or "license" for more information.
>>> import vars
>>> vars.PI, vars.TWOPI
(3.1415926535900001, 6.2831853071800001)
My variables are truncated at ~12 decimal points of precision.
Removing the .pyc file makes things "better" again...
presto:~$ rm vars.pyc
presto:~$ python
Python 2.0 (#6, Nov 16 2000, 12:32:08)
[GCC 2.95.2 20000220 (Debian GNU/Linux)] on linux2
Type "copyright", "credits" or "license" for more information.
>>> import vars
>>> vars.PI, vars.TWOPI
(3.1415926535897931, 6.2831853071795862)
Any idea why this is happening?
Thanks a bunch,
Scott
--
Scott M. Ransom Address: Harvard-Smithsonian CfA
Phone: (617) 495-4142 60 Garden St. MS 10
email: ransom at cfa.harvard.edu Cambridge, MA 02138
GPG Fingerprint: 06A9 9553 78BE 16DB 407B FFCA 9BFA B6FF FFD3 2989
More information about the Python-list
mailing list