pyc 文件与 python 的次要版本无关吗?

发布于 2024-09-25 06:06:50 字数 428 浏览 0 评论 0原文

是否可以安全地加载使用不同次要版本的 python 生成的 pyc 文件?
例如 2.5.1 和 2.5.5?

我的猜测是,幻数不会随着次要版本的变化而改变。
如果我引用这个文件 import.c 幻数对应于变量 pyc_magic (等于 MAGIC 或 MAGIC+1 )

文件注释如下:

拒绝其他 Python 版本生成的 .pyc 文件的魔法词。 它应该针对字节码的每个不兼容更改而更改。

我没有看到 python 小版本的不同数字,但我们可以假设它将来不会改变吗?

Is it possible and safe to load pyc files made with a different minor version of python?
For instance 2.5.1 with 2.5.5?

My guess is that the magic number does not change with minor versions.
If I refer to this file import.c
the magic number corresponds to the variable pyc_magic ( equals MAGIC or MAGIC+1 )

The file comments say:

Magic word to reject .pyc files generated by other Python versions.
It should change for each incompatible change to the bytecode.

I don't see different number for python minor versions, but can we assume it won't change in the future?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

棒棒糖 2024-10-02 06:06:50

你不能假设它不会改变。每当我需要分发 .pyc 文件而不是可读的 .py 文件时,我最终也会发布一个 Python 二进制文件。

You can't assume that it won't change. Whenever I've needed to distribute .pyc files instead of readable .py files, I've ended up shipping a Python binary too.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文