zipimport

Jonathan Brady nospam at denbridgedigital.com
Wed May 4 13:10:52 EDT 2005


"Gabriele *Darkbard* Farina" <darkbard at extending-php.net> wrote in message 
news:fV6ee.1330776$35.49663947 at news4.tin.it...
> Hi,
>
> I have a zip file structured like this:
>
> mymodule.zip\
>   module1.py
>   submodule\
>    submodule1.py
>
> I tried to load submodule.submodule1 using this pice of code:
>
> import zipimport
>
> z = zipimport.zipimporter("mymodule.zip")
> z.load_module("submodule.submodule1")
>
> but it does not work (load_module raises an exception)
>
> why?

try z.load_module("submodule/submodule1") instead.

Or in otherwords replace the dot with a slash, now quoting from the docs 
"'fullname' must be the fully qualified (dotted) module name.".  The dotted 
part of that doesn't seem to be correct, at least with the version of python 
(2.3.4) I'm running.

Anyway personally I find:

import sys
sys.path.insert(0, 'mymodule.zip')
import submodule.submodule1

a much cleaner way of thinking about this.

-- 
Jonathan 





More information about the Python-list mailing list