[Python-Dev] __file__

Greg Ewing greg.ewing at canterbury.ac.nz
Mon Mar 1 00:35:17 CET 2010

Floris Bruynooghe wrote:

> Can't it look for a .py file in the source directory first (1st stat)?
> When it's there check for the .pyc in the cache directory (2nd stat,
> magic number encoded in filename), if it's not check for .pyc in the
> source directory (2nd stat + read for magic number check).

Yes, although that would then incur higher stat overheads for
people distributing .pyc files. There doesn't seem to be a
way of pleasing everyone.

This is all assuming that the extra stat calls are actually
a problem. Does anyone have any evidence that they would
really take significant time compared to loading the module?
Once you've looked for one file in a given directory, looking
for another one in the same directory ought to be quite fast,
since all the relevant directory blocks will be in the
filesystem cache.


More information about the Python-Dev mailing list