[Python-Dev] importing .pyc-files generated by Python 1.5.2 in Python 1.6. Why not?

Guido van Rossum guido@python.org
Thu, 25 May 2000 10:51:44 -0500

Given Christian Tismer's testimonial and inspection of marshal.c, I
think Peter's small patch is acceptable.

A bigger question is whether we should freeze the magic number and add
a version number.  In theory I'm all for that, but it means more
changes; there are several tools (e.c. Lib/py_compile.py,
Tools/freeze/modulefinder.py and Tools/scripts/checkpyc.py) that have
intimate knowledge of the .pyc file format that would have to be
modified to match.

The current format of a .pyc file is as follows:

bytes 0-3   magic number
bytes 4-7   timestamp (mtime of .py file)
bytes 8-*   marshalled code object

The magic number itself is used to convey various bits of information,
all implicit:

- the Python version
- whether \r and \n are swapped (some old Mac compilers did this)
- whether all string literals are Unicode (experimental -U flag)

The current (1.6) value of the magic number (as a string -- the .pyc
file format is byte order independent) is '\374\304\015\012' on most
platforms; it's '\374\304\012\015' for the old Mac compilers
mentioned; and it's '\375\304\015\012' with -U.

Can anyone come up with a proposal?  I'm swamped!

--Guido van Rossum (home page: http://www.python.org/~guido/)