Home > Backend Development > Python Tutorial > Python是编译运行的验证方法

Python是编译运行的验证方法

WBOY
Release: 2016-06-10 15:18:12
Original
1129 people have browsed it

虽然Python被说成是一种解释型语言,但是实际上,Python源程序要先经过编译,然后才能运行。

与Java语言类似,Python源程序编译之后得到的是字节码,交由Python虚拟机来运行。

关于这一点,我们可以这样来验证:

复制代码 代码如下:

#!/usr/bin/python
 
print "position1"
1_syntax_error_identifier
print "position2"

将它保存为program.py,然后在shell窗口中运行它:
复制代码 代码如下:

root@dell:~$ ./program.py
  File "./program.py", line 4
    1_syntax_error_identifier
                            ^
SyntaxError: invalid syntax
root@dell:~$


从这里可以看出,如果Python是纯粹解释运行的话,那么它应该输出position1。
如果是编译运行的话,首先应该发现源代码中的语法错误,这正是本例展示的情况。
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template