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

"Martin v. Löwis" martin at v.loewis.de
Wed Nov 8 06:18:43 CET 2006


Greg Ewing schrieb:
> One thing I should add is that if you try to import
> a module that wasn't there before, the interpreter will
> notice this and has the opportunity to update its idea
> of what's on the disk.

How will it notice that it wasn't there before? The
interpreter will see that it hasn't imported the module;
it can't know whether it was there before while trying
to resolve the import: when looking at a directory in
sys.path, it needs to decide whether to use the directory
cache or not. If the directory is not in the cache, it
might be one of three things:
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?

Regards,
Martin


More information about the Python-Dev mailing list