checking pyc files against source code

Andrew Wilkinson ajw126 at NOSPAMyork.ac.uk
Tue May 20 07:38:17 EDT 2003


I believe that Python simply looks at the date/time stamps on the files. If
the last modification time on the .py file is after that of the .pyc file
then the .pyc file is recreated.

The os.stat function
(http://www.python.org/doc/current/lib/module-stat.html) should be able to
help you out here.

HTH,
Andrew Wilkinson

Jeremy Lowery wrote:

> I've implemented a new loader using ihooks, overriding the load_source
> method. new types have been added to get_suffixes in the hooks.
> (appending new ones to imp.get_suffixes()).
> 
> I also compile the source code into pyc files to make importing the
> modules in subsequent python runs faster (It is faster b/c the
> compilation of the custom files takes a good chunk of CPU time).
> 
> However, now when the custom files are edited, no change is seen until
> the .pyc file is deleted and then recreated by the import mechanism. I
> figure some os.getmtime stuff will be needed, but I"m not sure where.
> I would like it to behave like normal python files (If you change the
> .py file, the .pyc file is automatically recreated. Not sure where in
> the plumbing this happens). Any help?





More information about the Python-list mailing list