Question

To what extent is python bytecode compatible between releases. I'm not talking about python2.x to python3.x but say... Python33 to python34?

I am not after it for 'security' I use Cython to convert the bulk of a program to C, I do however use pyc file as a means to store some constants and pyc is preferable as it provides a file format that isn't easily changed unofficially. If someone wants something changed they can request via internal procedures

Such a pyc file only contains variables which are Int,float,list,dict,string in stf python. One class but it acts more as a container/struct.

Is this a big no or is this a try and see as some very basic python bytecode data is being stored

Was it helpful?

Solution

Python makes no guarantee about bytecode compatibility between versions. Don't rely on it.

In fact, a pyc file starts with a magic number that changes every time the marshalling code does, and python checks this number for compatibility. Since this code changes pretty much every version, so does the magic number. See Ned Batchelder's blog entry for details.

There are better ways of ensuring your files haven't been tampered with: checksums, for example.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top