imputils problem

Rainer Deyke root at
Sun Dec 10 13:30:47 EST 2000

"Magnus Heino" <magnus.heino at> wrote in message
news:90viai$slg$1 at
> > I've been having a problem with imputils: a module imported through a
> > custom
> > importer seems unable in import .pyd modules.  In particular, if I
> > the zipfile module though a custom importer, it is unable to find the
> > module.  Does anybody here know how to fix this?
> I have it working, but I had to tweek a bit.

Strangely enough, the problem went away when I moved zlib.pyd from the DLLs
subdirectory to the main directory of my program (which is a C++ program
with embedded Python 2.0).  The question: why did this change anything?
Does the default __import__ search directories that are not in sys.path?

> How are you doing things?

I took inspiration from the "small" Python distribution and provided a

--- ---
import marshal
import imputil
import cStringIO
import sys
import struct

class ArchiveImporter(imputil.Importer):

  def __init__(self, name):
    self.file = open(name, 'rb')
    (pos,) = struct.unpack('<l',
    self.toc = marshal.load(self.file)

  def get_code(self, parent, modname, fqname):
    name = fqname.replace('.', '/')
    if self.toc.has_key(name):
      return (0, self.__load(name), {})
    elif self.toc.has_key(name + '/__init__'):
      return (1, self.__load(name + '/__init__'), {})
      return None

  def __load(self, name):[name])
    return marshal.load(self.file)

if __name__ != '__main__':

--- end ---

Rainer Deyke (root at
Shareware computer games           - 
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor

More information about the Python-list mailing list