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

Francis Avila francisgavila at yahoo.com
Mon Nov 3 15:14:48 EST 2003


"Ellinghaus, Lance" <lance.ellinghaus at eds.com> wrote in message
news:mailman.385.1067888457.702.python-list at python.org...
> 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.

Actually, I Python will only use a compiled version if the source and the
compiled version have *exactly* the same date.  (This is a much better
approach anyway--suppose you want to run an older version?)

I only say this because I read "if it is newer" more often than not.

This reference has the rundown on the relationship between py-pyc-pyo files:
http://www.python.org/doc/current/tut/node8.html#SECTION00812000000000000000
0

--
Francis Avila





More information about the Python-list mailing list