By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,589 Members | 1,555 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,589 IT Pros & Developers. It's quick & easy.

Python - interpreted vs compiled

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
"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

P: n/a
thanks.

Jul 19 '05 #3

P: n/a
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.