[Python-Dev] Importing .pyc in -O mode and vice versa

Greg Ewing greg.ewing at canterbury.ac.nz
Thu Nov 9 00:29:43 CET 2006


Martin v. Löwis wrote:

> a) the directory cache is out of date, and you should
>    re-read the directory
> b) the module still isn't there, but is available in
>    a later directory on sys.path (which hasn't yet
>    been visited)
> c) the module isn't there at all, and the import will
>    eventually fail.
> 
> How can the interpreter determine which of these it
> is?

It doesn't need to - if there is no file for the module
in the cache, it assumes that the cache could be out
of date and rebuilds it. If that turns up a file, then
fine, else the module doesn't exist.

BTW, I'm not thinking of cacheing individual directories,
but scanning all the directories and building a single
qualified_module_name -> pathname mapping. If the cache
gets invalidated, all the directories along the path
are re-scanned, so a new module will be picked up
wherever it is on the path.

--
Greg


More information about the Python-Dev mailing list