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

Ellinghaus, Lance lance.ellinghaus at eds.com
Mon Nov 3 18:34:33 EST 2003


If I remember correctly, Yes. 
Python will import each module, compile if necessary, and then execute it.
This might cause additional modules to be compiled, loaded, etc.. But Python
will not import a module more than one time. Each additional time the import
is called for the same module, Python just binds a new reference into the
namespace.


Lance Ellinghaus
EDS - TWAI Operations
Phone: 214-922-5454
Cell: 940-597-4755



-----Original Message-----
From: seberino at spawar.navy.mil [mailto:seberino at spawar.navy.mil] 
Sent: Monday, November 03, 2003 3:28 PM
To: Ellinghaus, Lance
Cc: python-list at python.org
Subject: Re: Does python always need to compile ENTIRE program before it c
an start to run it???


Lance

Thanks for the info.  I agree that the initial script you
run must be compiled completely before it can execute.
Does "completely" =  all the imported modules too?

> When Python loads a module (.py file) from an 'import' statement, it 
> will see if there is an already compiled version in the same directory 
> and named the same except for the '.pyc' or '.pyo' extension. If it 
> finds this file AND it is newer than the corresponding source code 
> (.py) then it will load the saved compilation and then run it. If the 
> file is not found or it is older than the source, then Python will 
> compile the source, attempt to save the compiled version, and then it 
> will execute it.

The first word of your comments above is "When".  So if Python doesn't load
a module until 3 hours into the execution of a large Python program then
your recipe above (including compilation of module) won't get run until 3
hours AFTER execution starts right?

Chris





More information about the Python-list mailing list