Does python always need to compile ENTIRE program before it can start to run it???
peter at engcorp.com
Mon Nov 3 21:23:02 CET 2003
"Ellinghaus, Lance" wrote:
> Python always compiles your scripts to bytecode before it can be executed.
> It cannot and does not do partial compilation and execution.
> But this is not the whole story. Python does not always have to do the
> compilation phase. 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.
Minor correction: the .pyc file contains the timestamp of the .py file
from which it was compiled, and if they do not match (whether older *or*
newer) then the .py is recompiled and resaved. AFAIK.
More information about the Python-list