Why python compile the source to bytecode before interpreting?(为什么python在解释之前将源代码编译为字节码?)
问题描述
为什么python在解释之前要把源码编译成字节码?
Why python compile the source to bytecode before interpreting?
为什么不直接从源头解释?
Why not interpret from the source directly?
推荐答案
几乎没有解释器真正直接逐行解释代码——这实在是太低效了.几乎所有解释器都使用一些可以轻松执行的中间表示.此外,还可以对此中间代码进行小幅优化.
Nearly no interpreter really interprets code directly, line by line – it's simply too inefficient. Almost all interpreters use some intermediate representation which can be executed easily. Also, small optimizations can be performed on this intermediate code.
Python 还存储了这段代码,这对下次执行这段代码有很大的好处:Python 不再需要解析代码;解析是编译过程中最慢的部分.因此,字节码表示可以大大减少执行开销.
Python furthermore stores this code which has a huge advantage for the next time this code gets executed: Python doesn't have to parse the code anymore; parsing is the slowest part in the compile process. Thus, a bytecode representation reduces execution overhead quite substantially.
这篇关于为什么python在解释之前将源代码编译为字节码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么python在解释之前将源代码编译为字节码?


基础教程推荐
- 在 Python 中将货币解析为数字 2022-01-01
- Python 中是否有任何支持将长字符串转储为块文字或折叠块的 yaml 库? 2022-01-01
- matplotlib 设置 yaxis 标签大小 2022-01-01
- 在 Django Admin 中使用内联 OneToOneField 2022-01-01
- Kivy 使用 opencv.调整图像大小 2022-01-01
- Python,确定字符串是否应转换为 Int 或 Float 2022-01-01
- 比较两个文本文件以找出差异并将它们输出到新的文本文件 2022-01-01
- 对多索引数据帧的列进行排序 2022-01-01
- kivy 应用程序中的一个简单网页作为小部件 2022-01-01
- 究竟什么是“容器"?在蟒蛇?(以及所有的 python 容器类型是什么?) 2022-01-01