Python - interpreted vs compiled
bruno modulix
onurb at xiludom.gro
Fri Apr 15 09:46:39 EDT 2005
codecraig wrote:
> Hi,
> I have a question about Python. I know that it is an interpreted
> language,
Nope. A *language* is neither compiled nor interpreted. An
*implementation* of a language can use strict interpretation, byte-code
compilation + VM, or native code compilation (it could as well use
purely mechanical stuff or whatever).
CPython - the current reference implementation of Python - uses
byte-code compilation + VM. Jython too, but is relies on the Java
byte-code and VM. IronPython targets MS .NET CLR.
> meaning a python program is converted to binary on the fly
> each time it is run, or compiled.
Only the main script is recompiled each time - unless you compile it by
yourself. Imported code is (re)compiled only if necessary.
> What would be the purpose of compiling?
Having an intermediate representation that is faster to execute for the
VM. What is the purpose of compiling, be it to byte-code or to native
object code ?
> I guess the compiled python
> code (question, is compiled python code called byte code?
yes.
> is not readable since it is not plain text,
You mean human-readable ? Depends on which human reads it !-)
(NB : No, I can't read byte-code)
> which may be
> a reason for compiling...
No, this is an effect, not a cause.
Reverse-engineering Python byte-code is quite easy (idem for Java). This
is not meant to "protect" code. Neither is native object-code
compilation a protection against craking - or we wouldn't see so many
cracked applications on Windows machines...
> but why else??
Execution speed. A byte-code is kind of an assembly language for a
non-existing processor (hence the 'virtual machine' concept). This is
exactly the same motivation as for native-code compilation : not having
to tokenise/parse/translate the code each time it's runned.
The main difference here between Python and Java is that the Python
runtime takes care of those details for you instead of requiring you to
either manually recompile everything each time you make a change or use
a complex build system (that you'll have to - manually - maintain anyway).
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"
More information about the Python-list
mailing list