470,591 Members | 1,754 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,591 developers. It's quick & easy.

Python - interpreted vs compiled

Hi,
I have a question about Python. I know that it is an interpreted
language, meaning a python program is converted to binary on the fly
each time it is run, or compiled.
What would be the purpose of compiling? I guess the compiled python
code (question, is compiled python code called byte code?..if not, what
is it called?) is not readable since it is not plain text, which may be
a reason for compiling...but why else??

Thanks.

Jul 19 '05 #1
3 5078
"codecraig" wrote:
I have a question about Python. I know that it is an interpreted
language, meaning a python program is converted to binary on the fly
each time it is run, or compiled.
What would be the purpose of compiling? I guess the compiled python
code (question, is compiled python code called byte code?..if not, what
is it called?) is not readable since it is not plain text, which may be
a reason for compiling...but why else??


the Python runtime runs custom object code ("byte codes") on a virtual machine.
the compilation process converts source code to object code. to speed things up,
the object code (or byte code, if you prefer) is stored on disk, so it can be reused
the next time the program is run.

</F>

Jul 19 '05 #2
thanks.

Jul 19 '05 #3
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 'o****@xiludom.gro'.split('@')])"
Jul 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

28 posts views Thread by Maboroshi | last post: by
12 posts views Thread by Anon | last post: by
114 posts views Thread by Maurice LING | last post: by
9 posts views Thread by abisofile | last post: by
118 posts views Thread by 63q2o4i02 | last post: by
145 posts views Thread by Dave Parker | last post: by
53 posts views Thread by Vicent Giner | last post: by
39 posts views Thread by cm_gui | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.