Python解释器问题。

Python解释器问题。

问题描述:



-----开始PGP签名消息-----

哈希:SHA1


大家好


我是一名自学python的初学者,我非常享受它。

作为一种语言,它很棒,我真正善待学习,我实际上找到它很有趣

学习语言heh


无论如何我的帖子.....


前几天我和其他几个人讨论过古老的解释

v编译语言问题。

有人在说,


你无法击败编译语言。

"解释脚本语言如python只是为了减慢他说。


嗯我同意他的说法,比如C或任何其他编译的
语言,比如python和
$ b $等语言b [我敢在这里提到这个词]''perl'',在某些情况下会慢一些;


但是!!,我说,他们也更多在很多其他方面都很有优势。

很好。


好​​吧,几分钟后,另一位Python冠军进入辩论,并且

通过这样说就把所有东西都改成了,


Python也是一种编译语言,并没有使用翻译器,它是

使用Python VM


嗯,我很震惊,第一次大声笑,愤慨,告诉他Python确实

确实有一个解释器和python是一种解释性语言,而

也提醒他我也更喜欢python到其他语言。


我问他,那么,如果n,我的硬盘驱动器上的是什么ot Python

口译员?"


他回答说它不是解释器而且是Python编译器和VM

做了我所说的。

他继续解释所谓的口译员。我指的是

不存在,以及python在获取python源代码时所做的事情,或者

[在这个词上发抖]脚本,是将python源代码编译成

python字节代码,然后将编译后的数据传递给python VM,运行




所以我的问题是这个,


这一切都是真的吗?是不是说实际上python没有一个

解释器,而是它有一个编译器和VM来运行python

代码?


请原谅我,如果所有这些听起来对你经验丰富的类型来说都很简单,那么
Python是我的第一语言,虽然我很喜欢它并且学习很好/>
稳定率,python仍然是我的,第一种计算机语言。


提前致谢..

Anon >


- -

*************

可以比较想象力亚当的梦想 -

他醒来后发现它是真的。

John Keats。

********* ****

----- BEGIN PGP SIGNATURE -----

版本:PGP 8.0


iQA / AwUBQT3kwi / z2sM4qf2WEQLKsQCcDwg03n7KYM7OmGRVjCCoCUk8PpkAn2Pa

EEwtRUMnMLHi + iYtIqR1mAgT

= o / 5V

----- END PGP SIGNATURE -----


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello all

I am a beginner teaching myself python, and I am enjoying it immensely :)
As a language it is great, I real treat to study, I actually find it fun to
study the language heh

Anyways to the point of my post.....

The other day I was talking with a few others about the age old Interpreted
v compiled language issue.
Were one person was saying,

"You cannot beat a compiled language."
"Interpreted scripting languages like python are just to slow" he said.

Well I agreed with him that compared to say C or any other compiled
language, languages like python and
[dare I mention the word here] ''perl'', are slower in some cases;

"But!!", I said, "they are also more advantageous in many other ways as
well."

Well, after a few minutes, another Python champion came into the debate, and
turned everything on it''s head by saying this,

"Python is also a compiled language, and it doesn''t use an interpreter, it
uses the Python VM"

Well I was shocked at first lol, and indignant, telling him that Python does
indeed have an interpreter and python was an interpreted language, while
also reminding him that I also prefer python to to other languages as well.

I asked him, "Well what is sitting on my hard drive if not the Python
Interpreter?"

He replied that it wasn''t an interpreter and was the Python compiler and VM
that did what I was refering to.
He went on to explain that the so called, "Interpreter" I was referring to
didn''t exist, and that what python does when it gets python source, or
[shudders at the word] "script", is to compile the python source into
python byte code and then pass that compiled data to the python VM for
running.

So my question is this really,

Is all of that true? is it right to say in fact that python doesn''t have an
interpreter, but rather it has a compiler and VM for running the python
code?

Please forgive me if all this sounds so simple to you experienced types,
Python is my 1st language, and while I am loving it and learning at a good
steady rate, python is still my, "first computer language".

Thanks in advance..
Anon


- --
*************
The Imagination may be compared to Adam''s dream-
he awoke and found it truth.
John Keats.
*************
-----BEGIN PGP SIGNATURE-----
Version: PGP 8.0

iQA/AwUBQT3kwi/z2sM4qf2WEQLKsQCcDwg03n7KYM7OmGRVjCCoCUk8PpkAn2Pa
EEwtRUMnMLHi+iYtIqR1mAgT
=o/5V
-----END PGP SIGNATURE-----

" Anon" <顾*** @ My.email.address.scum.com>写道:
"Anon" <gu***@My.email.address.scum.com> wrote:
这一切都是真的吗?是不是说实际上python没有一个
解释器,而是它有一个编译器和VM来运行python
代码?
Is all of that true? is it right to say in fact that python doesn''t have an
interpreter, but rather it has a compiler and VM for running the python
code?


>
Python源代码确实被转换为中间形式(字节

代码),然后在虚拟机上执行。非常像Java

是。是否要将此称为解释或编译或是的,我想是个人意见。



Python source code is indeed converted into an intermediate form (byte
code) which is then executed on a virtual machine. Very much like Java
is. Whether you want to call this "interpreted" or "compiled" is, I
suppose, a matter of personal opinion.


Anon< gu *** @ My.email.address.scum。 COM&GT;写道:

...
Anon <gu***@My.email.address.scum.com> wrote:
...
这一切都是真的吗?是不是说实际上python没有一个
解释器,而是它有一个编译器和VM来运行python
代码?
Is all of that true? is it right to say in fact that python doesn''t have an
interpreter, but rather it has a compiler and VM for running the python
code?


>
Python确实是基于编译器到字节码加上一个VM,比如Java。


但是,Python需要额外的一步来从

两者的组合 - 毕竟,将源代码编译为字节码,然后将
转换为VM _is_ easy。所以,任何时候你在源字符串或文件上使用exec,eval或execfile,实际上,对于所有意图和目的,你都在使用一个b
$ b翻译,即使它是'b $ b b与烟雾和镜子,哎呀,我的意思是编译器和VM'。


同样适用于任何你在交互式>>>处输入提示 -

这个事实,无论你输入什么来源首先被编译成字节码,然后是
然后将该字节码移交给VM执行,不是

问题给你...在实践中你有一个翻译,即使

内心深处它只是一个编译器+一个VM! - )

Alex



Python is indeed based on a compiler to bytecode plus a VM, like Java.

However, Python goes the extra step to make an interpreter out of the
combination of the two -- after all, compiling source to bytecode and
then handing the bytecode over to the VM _is_ easy. So, any time you''re
using exec, eval, or execfile on source strings or files, in practice,
to all intents and purposes, you ARE using an interpreter, even if it''s
put together with smoke and mirrors, oops, I mean compilers and VM''s.

Similarly for anything you type at the interactive >>> prompt -- the
fact that whatever source you type gets compiled into bytecode first,
and then that bytecode is handed over to the VM for execution, is no
problem to you... in practice you DO have an interpreter, even though
"deep down" it''s just a compiler + a VM!-)
Alex


On Tue,2004年9月7日12:56:40 -0400 ,Roy Smith写道:
On Tue, 07 Sep 2004 12:56:40 -0400, Roy Smith wrote:
是否要将此称为解释。或编译或是的,我想是个人意见的问题。
Whether you want to call this "interpreted" or "compiled" is, I
suppose, a matter of personal opinion.




对于那些

单词,两者。


它被编译成一个然后被解释的形式。


合适的定义,例如:


*编译:以一种格式(.py Python源

文件)获取一些语义含义并将其转换为其他格式(.pyc编译源代码) )与

等效的语义。 (这是一个非常一般的定义。)

*解释:要运行一个不是以原始二进制格式编码的程序,而是执行程序的处理器通过提供一个虚拟机
运行的
执行程序。


Java,.NET和其他很多东西现在以这种方式工作。这一天即将快速接近,如果还没有在这里,拒绝解释

语言将拒绝大多数正在运行的代码作为非真实代码。



It is, for some suitable (but widely-agreed upon) definitions of those
words, both.

It is compiled into a form that is then interpreted.

Suitable definitions, for instance:

* Compile: To take some semantic meaning in one format (.py Python source
files) and convert it to some other format (.pyc compiled source) with
equivalent semantics. (This is a very general definition.)
* Interpret: To run a program not encoded in the native binary format of
the processor executing the program by providing it with a virtual machine
to run on that executes the program.

Java, .NET, and a lot of other things work this way now. The day is
rapidly approaching, if not already here, where rejecting "interpreted"
languages is to reject the majority of running code as "not real code".