[Tutor] 2nd bonehead question...

Magnus Lycka magnus@thinkware.se
Sun Jan 5 15:44:03 2003


At 16:19 2002-12-21 -0800, Sean 'Shaleh' Perry wrote:
> > .pyc is a .py file compiled into byte-code, a binary
> > format that the python interpreter reads. These files
> > are created automatically when a python module is
> > imported, if there isn't already an updated .pyc file.
>
>taken a step further, the interpreter has some magic to use the .pyc first if
>it exists otherwise it makes one from the .py file.  There is logic there to
>see if the pyc is older than the py and if so recreate it as well.

Yes, this is good to know, since it might bite you in
some cases:

- You open an archive (.zip, .tar etc) with .py-files. You
change a file x.py, and then run the program y.py, and x.pyc
is created as you do "import x" in y.py. You see that your
fix was bad, and you revert to the original x.py by extracting
it from the archive file again. You do this with a command that
preserves time settings for the file, and to your surprise, the
bug you just backed out of is still in your program, despite
the fact that it's gone from the source...

- You make a change in foo.py module, and a foo.pyc is created.
You then realize that you have previously changed the date in
your computer to January 5, 2004 by accident. (Stupid Windows...)
You correct this, and make further changes to foo.py, but they don't
seem to be reflected in your program next time you try it...

- You use clearcase with dynamic views for source control, and you
check out an earlier version of a .py-file.

In all these situations I think Python will be tricked into using an
invalid .pyc-file.

When in doubt...just delete your .pyc-files.


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se