Python compilers

Peter Hansen peter at engcorp.com
Wed Apr 3 01:27:11 EST 2002


Rob Hazlewood wrote:
> 
> I'm thinking of learning python, and am a little confused as to the
> overall structure of python programming.
> 
> Would I be right in saying that Python is an interpreted language?

Yes.

> I know it can be run as an interpreted language, however I seem to
> remember people talking about python compilers.

Yes.

What do those two things mean to you?  Python, as with Java, is 
compiled to "bytecode", which is like machine language for a
non-existent processor, sometimes called a virtual machine.
Java calls it that, while Python calls it "the interpreter".
They're basically the same thing.

Unlike with Java, Python compilation is transparent to the
user in most cases, and the resulting .pyc files are cached
on the hard drive and the compilation step is skipped the 
next time the program is run, if the source files do not change.

> Do Python compilers exist? are they efficient?

Yes, and no.  Mostly no, not in the sense you probably mean.
Partially yes, in that sense. :)  Definitely yes if you just
mean "can you get a standalone executable file?", using
several means.  At heart, Python is very dynamic and apparently
somewhat difficult to handle with a compiler.  There have
been and are various efforts along those lines but few
consider it a really high priority issue.

> If there is a python compiler, surely it would be able to generate code
> that is as efficient as a C compiler, resulting in what would be the
> best available OO language? (having simplicity, speed)

No, but relatively few people are overly concerned about that.
Most programmers who are greatly concerned about speed actually
have no particular requirement in mind, they just want "more".
Far too often this is a waste of their time.  Some people look
at ways to optimize programs that take 60 seconds to run and
get run once a day.  In C the same program might take 2 seconds,
but so what?  It might also crash, and it took ten times longer
to develop...

> What is the performance of python like compared to other languages such
> as C and java?

Similar to Java, between 10 and 100 times slower than C, depending
on the application.  The key thing to remember is that few programs
really need maximum performance, and most programs take far more
time to develop than they ever spend running.  Python accelerates
the development well beyond C, or even Java, and is considered
a highly maintainable language as well.  If raw performance
is required, one uses or writes extension modules which are
coded in C and integrated cleanly with Python.

-Peter



More information about the Python-list mailing list