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

本文翻译自:What do the python file extensions, .pyc .pyd .pyo stand for?

What do these python file extensions mean? 这些python文件扩展名是什么意思?

  • .pyc .pyc文件
  • .pyd .pyd
  • .pyo .pyo

What are the differences between them and how are they generated from a *.py file? 它们之间有什么区别?它们是如何从* .py文件生成的?


#1楼

参考:https://stackoom.com/question/b15j/python文件扩展名是什么-pyc-pyd-pyo代表什么


#2楼

  • .py - Regular script .py - 常规脚本
  • .py3 - (rarely used) Python3 script. .py3 - (很少使用)Python3脚本。 Python3 scripts usually end with ".py" not ".py3", but I have seen that a few times Python3脚本通常以“.py”而不是“.py3”结尾,但我已经看过几次
  • .pyc - compiled script (Bytecode) .pyc - 编译脚本(字节码)
  • .pyo - optimized pyc file (As of Python3.5, Python will only use pyc rather than pyo and pyc) .pyo - 优化的pyc文件(截至Python3.5,Python只使用pyc而不是pyo和pyc)
  • .pyw - Python script to run in Windowed mode, without a console; .pyw - 在没有控制台的情况下以窗口模式运行的Python脚本; executed with pythonw.exe 用pythonw.exe执行
  • .pyx - Cython src to be converted to C/C++ .pyx - 要转换为C / C ++的Cython src
  • .pyd - Python script made as a Windows DLL .pyd - 作为Windows DLL的Python脚本
  • .pxd - Cython script which is equivalent to a C/C++ header .pxd - Cython脚本,相当于C / C ++标头
  • .pxi - MyPy stub .pxi - MyPy存根
  • .pyi - Stub file ( PEP 484 ) .pyi - 存根文件( PEP 484
  • .pyz - Python script archive ( PEP 441 ); .pyz - Python脚本存档( PEP 441 ); this is a script containing compressed Python scripts (ZIP) in binary form after the standard Python script header 这是一个包含标准Python脚本头之后的二进制形式的压缩Python脚本(ZIP)的脚本
  • .pywz - Python script archive for MS-Windows ( PEP 441 ); .pywz - MS-Windows的Python脚本存档( PEP 441 ); this is a script containing compressed Python scripts (ZIP) in binary form after the standard Python script header 这是一个包含标准Python脚本头之后的二进制形式的压缩Python脚本(ZIP)的脚本
  • .py[cod] - wildcard notation in ".gitignore" that means the file may be ".pyc", ".pyo", or ".pyd". .py [cod] - “.gitignore”中的通配符,表示该文件可能是“.pyc”,“。pyo”或“.pyd”。

A larger list of additional Python file-extensions (mostly rare and unofficial) can be found at http://dcjtech.info/topic/python-file-extensions/ 可以在http://dcjtech.info/topic/python-file-extensions/找到更大的其他Python文件扩展名列表(主要是稀有和非官方的)。


#3楼

  1. .py : This is normally the input source code that you've written. .py :这通常是您编写的输入源代码。
  2. .pyc : This is the compiled bytecode. .pyc :这是编译后的字节码。 If you import a module, python will build a *.pyc file that contains the bytecode to make importing it again later easier (and faster). 如果你导入一个模块,python将构建一个包含字节码的*.pyc文件,以便以后更容易(更快)地再次导入它。
  3. .pyo : This is a *.pyc file that was created while optimizations ( -O ) was on. .pyo :这是在启用优化( -O )时创建的*.pyc文件。
  4. .pyd : This is basically a windows dll file. .pyd :这基本上是一个windows dll文件。 http://docs.python.org/faq/windows.html#is-a-pyd-file-the-same-as-a-dll http://docs.python.org/faq/windows.html#is-a-pyd-file-the-same-as-a-dll

Also for some further discussion on .pyc vs .pyo , take a look at: http://www.network-theory.co.uk/docs/pytut/CompiledPythonfiles.html (I've copied the important part below) 关于.pyc vs .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. 使用-O标志调用Python解释器时,将生成优化代码并将其存储在“.pyo”文件中。 The optimizer currently doesn't help much; 优化器目前没有多大帮助; it only removes assert statements. 它只删除断言语句。 When -O is used, all bytecode is optimized; 当使用-O时,所有字节码都被优化; .pyc files are ignored and .py files are compiled to optimized bytecode. .pyc文件被忽略,.py文件被编译为优化的字节码。
  • 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. 将两个-O标志传递给Python解释器(-OO)将导致字节码编译器执行优化,在某些极少数情况下可能导致程序出现故障。 Currently only __doc__ strings are removed from the bytecode, resulting in more compact '.pyo' files. 目前只有__doc__字符串从字节码中删除,从而产生更紧凑的'.pyo'文件。 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; 从'.pyc'或'.pyo'文件读取程序时,程序运行速度不比从'.py'文件读取时快; the only thing that's faster about '.pyc' or '.pyo' files is the speed with which they are loaded. 关于'.pyc'或'.pyo'文件,唯一更快的是它们加载的速度。
  • 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. 通过在命令行上给出其名称来运行脚本时,脚本的字节码永远不会写入“.pyc”或“.pyo”文件。 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. 也可以直接在命令行上命名'.pyc'或'.pyo'文件。

Note: 注意:

On 2015-09-15 the Python 3.5 release implemented PEP-488 and eliminated .pyo files. 在2015-09-15, Python 3.5版本实现了PEP-488并删除了.pyo文件。 This means that .pyc files represent both unoptimized and optimized bytecode. 这意味着.pyc文件代表未优化和优化的字节码。

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值