Next: Executable Python scripts Up: The Interpreter and Previous: The Module Search

``Compiled'' Python files

As an important speed-up of the start-up time for short programs that use a lot of standard modules, if a file called foo.pyc exists in the directory where foo.py is found, this is assumed to contain an already-``compiled'' version of the module foo. The modification time of the version of foo.py used to create foo.pyc is recorded in foo.pyc, and the file is ignored if these don't match.

Whenever foo.py is successfully compiled, an attempt is made to write the compiled version to foo.pyc. It is not an error if this attempt fails; if for any reason the file is not written completely, the resulting foo.pyc file will be recognized as invalid and thus ignored later.


guido@cwi.nl