Python compilation ??

Steve Holden steve at
Tue Jul 3 00:03:29 CEST 2007

Jean-Paul Calderone wrote:
> On Mon, 02 Jul 2007 16:14:41 -0400, Steve Holden <steve at> wrote:
>> Evan Klitzke wrote:
>>> On 7/2/07, Cathy Murphy <cathy at> wrote:
>>>> Is python a compiler language or interpreted language. If it is interpreter
>>>> , then why do we have to compile it?
>>> It's an interpreted language. It is compiled into bytecode (not
>>> machine code) the first time a script is run to speed up subsequent
>>> executions of a script.
>> While the flavor of this answer is correct, in strict point of fact
>> Python *doesn't* compile the scripts it executes, only the modules that
>> are imported.
>> That's why you will occasionally see a very small Python program that
>> just calls functions imported from much larger modules. This avoids
>> spending the time that would otherwise have to be spent recompiling a
>> large script at each execution.
> Hey Steve,
> To nit pick :)  Wouldn't you say it is more accurate to say that it
> does compile the scripts (by which we mean the "main" file - either
> the one passed as an argument to the interpreter on the command line,
> or the one with a #! at the top which gets respected, or the .py file
> on Windows which is associated with python.exe as its interpreter),
> but that it doesn't save the results of this compilation to a file to
> be used next time?
> Jean-Paul

Absolutely. I should, of course, have said that only imported modules 
have the results of the compilation stored as a .pyc file.

One must presume this is to save the file write time during development 
when the program is almost always different fro the last time you ran it.

Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd 
Skype: holdenweb
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------

More information about the Python-list mailing list