compatbility of .pyc files

"Martin v. Löwis" martin at v.loewis.de
Tue Feb 22 21:10:44 EST 2005


Blair Hall wrote:
> Are the .pyc's usable without recompilation between 'minor'
> releases of the interpretter (e.g., 2.3.1 -> 2.3.2 -> etc)?

Yes.

> I presume that the .pyc's are NOT compatible
> across more major releases (e.g., 2.3.x -> 2.4.x)?

Correct.

> Is there a hard and fast rule about compatibility across
> releases that I can rely on?

Each Python version uses a "magic", as returned by
imp.get_magic(). Whenever that changes (and it will at
worst change between 2.x, 2.x+1), you need to recompile
the .pyc files.

If you pass it an "old" pyc file (i.e. one with an
incorrect magic), Python will silently ignore the .pyc
file, use the source, and attempt to regenerate the
.pyc file.

Regards,
Martin



More information about the Python-list mailing list