[Python-Dev] PEP 273: Import Modules from Zip Archives

Guido van Rossum guido@python.org
Mon, 29 Oct 2001 10:13:14 -0500


[Finn]
> > So python packages and modules can exists *only* at the top level? That
> > would conflict somewhat with jython where at would be common to put
> > python modules into the same .zip file as java classes and java classes
> > also wants to own the root of a zip file.
> > 
> > In the current implementaion in jython, we can put python modules under
> > any path and add the zipfile!path to sys.path:
> > 
> >    sys.path.append("/path/to/zipfile.zip!Lib")
> > 
> > which will look for Lib/Q/R/modfoo.py (and Lib/Q/R/modfoo$py.class) in
> > the archive.

[JimA]
> I am confused.  Zip archives are equivalant to subdirectories, so there
> is no requirement to have anything at the top level.  Your example seems
> to imply a second search path besides sys.path.

I think Finn simply means that the zipfile may have some redundant
initial suffix to all filenames (e.g. "Lib/") which could be an
artefact of how the zip file is created (zip up this directory) or
intended as an aid for other uses of the zipfile, like unpacking.  (In
the tar world, it's considered impolite not to have a common prefix;
without that, untarring can too easily populate an innocent user's
home directory with thousands of untarred files.)

> BTW, the code uses ".zip" as the archive flag,
> not a special character '!'.

That's cool.

--Guido van Rossum (home page: http://www.python.org/~guido/)