python bytecode compatibility

大兔子大兔子 提交于 2019-12-30 11:04:30

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/22449524/python-bytecode-compatibility

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!