pyc files located elsewhere?
jcarlson at uci.edu
Sat Oct 16 23:11:27 CEST 2004
> Josiah Carlson wrote:
> > I don't know if it is possible to automatically write to a different
> > path, but I /think/ one can /turn off/ writing .pyc files, but it would
> > necessarily make running the script slower (you don't get cached .pyc
> > files, so every import requires a py->pyc compilation).
> Just to clarify (and I don't know turning that feature off is really
> possible, so maybe it's a useless point), but not *every* import will
> require the compilation. The first import of any given module will
> require the compilation, each time you run the application. If a
> module is imported fifty times, all but the first just retrieve
> the module from sys.modules, same as normal.
Right, but if you have 50 modules that are imported (50 unique module
files), then you still have to compile those 50 every time. The speed
hit really depends on the size of the application, and how often
> (Is what you describe really possible? I've never heard of it.)
I know that importing from a non-writable location disables writing of
pyc files (zip imports, etc.), and I am fairly certain it can be done
with an import hook, though never having need for it, I've never tried.
More information about the Python-list