zipimport

  • Thread starter Gabriele *Darkbard* Farina
  • Start date
G

Gabriele *Darkbard* Farina

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?

tnx, bye
 
J

Jonathan Brady

Gabriele *Darkbard* Farina said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top