PEP 304 - Controlling generation of bytecode files
Skip Montanaro
skip at pobox.com
Wed Jan 29 14:10:47 EST 2003
Ian> It would please me to not see .pyc files sitting all over the
Ian> place. Really, it's not anal or anything -- I don't horribly mind
Ian> them. But I know I would feel happier not seeing them, and I like
Ian> feeling happy. This would make possible that dream of a .pyc-less
Ian> world. I know I am a happier person for having Emacs put its ~
Ian> backups into a separate directory -- happiness through cleanliness
Ian> is not just a fantasy! And I was just thinking about how I didn't
Ian> like .pyc files two days ago...
You can accomplish that with this proposal (though users can override your
accomplishments). If you set sys.bytecodebase to None in site.py, no .pyc
files will be written. I think that's where I will make the translation
from PYTHONBYTECODE base to sys.bytecodebase. You are free to override or
undo that.
Ian> The PEP should be unambiguous about the search path. In
Ian> particular, say /foo shows up in the search path before /bar, and I
Ian> create a file /foo/file.py, use it and decide it should go in
Ian> /bar/file.py. I likely won't delete /pycfiles/foo/file.pyc, but it
Ian> would be *horrible* if that outdated file got imported. I can
Ian> easily imagine tearing my hair out for some time if that happened
Ian> and I didn't notice it.
That outdated .pyc file will get imported. It's your responsibility to
manage your directory tree properly. If you think this is a bug, please
file a report on SF (though I don't whoever responds will consider it a
bug).
Here's one way to reproduce the behavior. Cd to /tmp and create oldpyc.py
with these contents:
import sys
sys.path = ["./foo", "./bar"] + sys.path
import minnie
Create directories ./foo and ./bar.
Now create /tmp/foo/minnie.py with these contents:
print "imported", __file__
Run "python oldpyc.py". It should report:
imported ./foo/minnie.py
Now move /tmp/foo/minnie.py to /tmp/bar/minnie.py but don't delete
/tmp/foo/minnie.pyc.
Run "python oldpyc.py" again. It should report:
imported ./foo/minnie.pyc
Skip
More information about the Python-list
mailing list