Import from zip file?

David LeBlanc whisper at oz.net
Mon Jan 20 20:20:55 CET 2003


Isn't import from zip/tgz/bzip supported in python 2.3, as well as extending
support for user written importers?

David LeBlanc
Seattle, WA USA

> -----Original Message-----
> From: python-list-admin at python.org
> [mailto:python-list-admin at python.org]On Behalf Of Bengt Richter
> Sent: Monday, January 20, 2003 9:51
> To: python-list at python.org
> Subject: Re: Import from zip file?
>
>
> On 20 Jan 2003 16:35:45 +0100, martin at v.loewis.de (Martin v.
> =?iso-8859-15?q?L=F6wis?=) wrote:
>
> >k.robert at gmx.de (Robert) writes:
> >
> >> What is the easyiest way to import modules/module-trees from zip
> >> files (Python 2.2)?
> >
> >Unpack the zip file, then add the directory to sys.path.
> >
> How deep is the dependence of import on the file system?
> I.e., what is the role of the file name ('.' name)* after the file data
> has been found and loaded? It seems like it's mainly to be recorded
> in sys.modules to prevent re-loading, so that sharing results.
>
> Is there a reason you couldn't have import recognize a zip or tgz file
> as a virtual file directory tree to search and import from there,
> given a little hint via alternate syntax, e.g.,
>
>     import foo from 'bar.zip' as baz  # note the quotes -- it's a
> file spec, not dotted module
>
> where foo could go in sys.modules and baz could be the local binding.
> baz.__name__ would be foo, and
>     sys.modules['foo'] is baz => True.
>
> Seems like any byte stream ought to be able to be made to work too, even
>
>     import spam from sys.stdin
>
> with no local as-alias, it would be spam, and spam.__name__ would be spam,
> resulting in sys.modules['spam'] is spam => True.
>
> and it could recognize a string after the from and open that as a
> normal file
> path spec without dotted notation, though you might even be able
> to introduce
> that specifically too, e.g.,
>
>     import hum.haw from '~/stuff/ho/hawfile' as foo
> and get
>     sys.modules['hum.haw'] is foo => True.
> (but leaving out sys.modules['hum'] I suppose).
>
> Regards,
> Bengt Richter
> --
> http://mail.python.org/mailman/listinfo/python-list






More information about the Python-list mailing list