python文件扩展名.pyc.pyd.pyo代表什么?

2024-03-29 06:35:23 发布

您现在位置:Python中文网/ 问答频道 /正文


Tags: python
2条回答
  • .py-常规脚本
  • .py3-(很少使用)Python3脚本。Python3脚本通常以“.py”结尾,而不是“.py3”,但我已经看过几次了
  • .pyc-编译脚本(字节码)
  • .pyo-优化的pyc文件(从Python3.5开始,Python将只使用pyc而不是pyo和pyc)
  • .pyw-在窗口模式下运行的Python脚本,不带控制台;用pythonw.exe执行
  • >强> Pyx<强> -Cython Src,转换为C/C++ +/LI>
  • .pyd-作为Windows DLL生成的Python脚本
  • >强> .pxd -Cython脚本,相当于C/C++头
  • .pxi-MyPy存根
  • .pyi-存根文件(PEP 484
  • .pyz-Python脚本存档(PEP 441);这是一个脚本,在标准Python脚本头之后包含二进制形式的压缩Python脚本(ZIP)
  • .pywz-Python script archive for MS Windows(PEP 441);这是一个脚本,在标准Python脚本头之后包含二进制形式的压缩Python脚本(ZIP)
  • .py[cod]-“.gitignore”中的通配符表示法,这意味着文件可以是“.pyc”、“.pyo”或“.pyd”。

http://dcjtech.info/topic/python-file-extensions/中可以找到更多的附加Python文件扩展名列表(通常是罕见的和非官方的)

  1. .py:这通常是您编写的输入源代码。
  2. .pyc:这是编译的字节码。如果您导入一个模块,python将构建一个包含字节码的*.pyc文件,以便以后更容易(更快)地再次导入它。
  3. .pyo:这是一个*.pyc文件,在优化(-O)打开时创建。
  4. .pyd:这基本上是一个windows dll文件。http://docs.python.org/faq/windows.html#is-a-pyd-file-the-same-as-a-dll

关于.pyc.pyo的进一步讨论,请看:http://www.network-theory.co.uk/docs/pytut/CompiledPythonfiles.html(我复制了下面的重要部分)

  • When the Python interpreter is invoked with the -O flag, optimized code is generated and stored in ‘.pyo’ files. The optimizer currently doesn't help much; it only removes assert statements. When -O is used, all bytecode is optimized; .pyc files are ignored and .py files are compiled to optimized bytecode.
  • Passing two -O flags to the Python interpreter (-OO) will cause the bytecode compiler to perform optimizations that could in some rare cases result in malfunctioning programs. Currently only __doc__ strings are removed from the bytecode, resulting in more compact ‘.pyo’ files. Since some programs may rely on having these available, you should only use this option if you know what you're doing.
  • A program doesn't run any faster when it is read from a ‘.pyc’ or ‘.pyo’ file than when it is read from a ‘.py’ file; the only thing that's faster about ‘.pyc’ or ‘.pyo’ files is the speed with which they are loaded.
  • When a script is run by giving its name on the command line, the bytecode for the script is never written to a ‘.pyc’ or ‘.pyo’ file. Thus, the startup time of a script may be reduced by moving most of its code to a module and having a small bootstrap script that imports that module. It is also possible to name a ‘.pyc’ or ‘.pyo’ file directly on the command line.

注意:

2015年9月15日,Python 3.5 release实施了PEP-488并删除了.pyo文件。 这意味着.pyc文件同时表示未优化和优化的字节码。

相关问题 更多 >