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

查看:166
本文介绍了在导入中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天全站免登陆