.pyc files??

Jeff Shannon jeff at ccvcorp.com
Thu Sep 2 16:56:15 EDT 2004


Peter Hansen wrote:

> Jeremy Jones wrote:
>
>> This file contains compiled bytecode that the Python interpreter 
>> uses.  If, in your example, filea.pyc exists and its timestamp is 
>> newer than filea.py, then the interpreter uses filea.pyc without even 
>> attempting to recompile it (which saves the time spent compiling in 
>> subsequent runs).  If filea.pyc doesn't exist, or its timestamp is 
>> older than filea.py, the Python interpreter compiles filea.py to 
>> bytecode and writes it to filea.pyc (if it has permissions to do so).
>
>
> Minor nit-picking:  I'm fairly sure that the interpreter just compares
> the timestamp for equality, not for "earlier than".  I could be
> wrong, but I think it's a case of "if the .pyc embedded timestamp
> doesn't match the timestamp of the corresponding .py file exactly,
> then recompile the .pyc file".
>
> And a quick test at the command line appears to confirm this...


Really?  All my .pyc files are timestamped later than the .py file that 
they were generated from, but they don't seem to be recreated when I 
import the module...

[ach]$ ls -l *.py*
-rwxr-xr-x    1 pick     pick         1709 Aug  3 18:36 http_multipart.py
-rw-r--r--    1 pick     pick         2437 Aug  4 00:12 http_multipart.pyc
[ach]$ python
Python 2.2.2 (#1, Feb 24 2003, 19:13:11)
[GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> import http_multipart
 >>>
[ach]$ ls -l *.py*
-rwxr-xr-x    1 pick     pick         1709 Aug  3 18:36 http_multipart.py
-rw-r--r--    1 pick     pick         2437 Aug  4 00:12 http_multipart.pyc
[ach]$

Jeff Shannon
Technician/Programmer
Credit International





More information about the Python-list mailing list