导入中python编译文件的优先级是什么? [英] What is the precedence of python compiled files in imports?

查看:32
本文介绍了导入中python编译文件的优先级是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Python 文件被编译为字节码 (*.pyc).

Python files are compiled to bytecode (*.pyc).

使用 Cython,您可以将它们编译为机器代码(Linux 中的 *.so).

Using Cython you can compile them to machine code (*.so in Linux).

如果两个文件在同一个文件夹下,同名下它们之间的优先级是什么?

If you use have both files in the same folder, under the same name what is the precedence between them?

是否有一种自动方法可以确保使用 *.so 文件而不是 *.pyc 文件?或者您必须在代码中明确执行(重命名等)?

Is there an automatic way to ensure that the *.so file is used instead of the *.pyc one? Or you have to do it explicitly in the code (renaming etc)?

推荐答案

Python 将首先加载 .so 文件.请参阅这个问题以获取python搜索的后缀的有序列表.

Python will load the .so file first. See this question for an ordered list of the suffixes that python searches for.

好吧,我会告诉你:

foo (a directory)
foo.so
foomodule.so
foo.py
foo.pyc

这篇关于导入中python编译文件的优先级是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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