What is the precedence of python compiled files in imports?

笑着哭i 提交于 2019-12-18 04:03:32

问题


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

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?

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)?


回答1:


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

Well, I'll just tell you:

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


来源:https://stackoverflow.com/questions/6584457/what-is-the-precedence-of-python-compiled-files-in-imports

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