python字节码兼容性 [英] python bytecode compatibility

查看:94
本文介绍了python字节码兼容性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

发行版之间python字节码在何种程度上兼容。
我不是说从python2.x到python3.x,而是说...从Python33到python34?

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

我不是为了安全性而追求它我使用Cython将程序的大部分转换为C,但是我确实使用pyc文件作为存储一些常量的方法,而pyc是首选,因为它提供了不容易被非正式更改的文件格式。如果有人要更改某些内容,可以通过内部过程

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

这样的pyc文件仅包含
变量,这些变量在stf中为Int,float,list,dict,string蟒蛇。
一个类,但它更多地充当容器/结构。

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.

这是一个很大的否还是这是一个尝试,可以看做是一些非常基本的python字节码数据正在存储

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

推荐答案

Python不保证版本之间的字节码兼容性。不要依赖它。

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

实际上,pyc文件以一个魔术数字开头,每次编组代码运行时魔术数字都会更改,并且python检查此数字的兼容性。由于此代码几乎每个版本都会更改,因此幻数也是如此。有关详细信息,请参见内德·巴切尔德的博客条目

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.

这篇关于python字节码兼容性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆