Does python always need to compile ENTIRE program before it can start to run it???

Peter Hansen peter at engcorp.com
Mon Nov 3 14:24:24 EST 2003


Christian Seberino wrote:
> 
> I can achieve something similar to Python's automatic compilation
> in C/C++ by making a script that compiles and runs my program like this:
> 
> make ; myprogram
> 
> I am trying to think of an advantage Python has over this hack....
> 
> Is it true that unlike C/C++ that Python programs can start executing
> before compilation is COMPLETELY done???  I think so but I'm not sure.

Yes, this is true.  Assuming (as would be the case in any serious 
program) your code is broken into appropriate modules, only the first
module loaded is compiled prior to its execution.  Other modules are
compiled on an as-needed basis, as they are imported for the first
time.  Also note that Python has automatic caching of the compiled
code in a .pyc file, and recompilation occurs only if the timestamp
of the source .py file is different than that stored in the .pyc file.

In essence, the above "hack", as you so aptly call it, has *no*
advantages over Python's approach, and Python makes it all transparent
anyway so you don't even need to worry about it.

-Peter




More information about the Python-list mailing list