Request for loading zipped modules in some context

Discussion in 'Python' started by Kay Schluehr, Jan 5, 2008.

  1. Kay Schluehr

    Kay Schluehr Guest

    When trying to import a module from a filesystem directory there are
    several possibilities. Most obviously one can use an import statement
    but if this is not sufficient one has also API functions. However
    these API functions don't seem to be consistent with each other.

    If one uses the builtin __import__ function one can import the module
    in some context i.e. one can pass locals and globals:

    __import__( name[, globals[, locals[, fromlist[, level]]]])

    If one uses the imp module instead one has several different
    possibilities to load a module ( load_source, load_compiled ) but none
    of them imports the module in some context.

    The situation becomes worse when using zipimport. The zipimport module
    provides methods get_code and load_module.
    <module 'mymodule' from 'myziparchive.zip\mymodule.py'>

    Using load_module returns a module object. One cannot initialize the
    module in some context though. One can also use get_code and use a
    code object:

    One can evaluate the code object but this won't give you much. It
    won't magically transform the code object into a module object being
    returned and cached. Creating a module object from a code object isn't
    possible AFAIK. The get_code method doesn't seem to be particular
    usefull.

    I'd like to see things being made more uniform - but uniform in the
    sense of providing the most powerfull options all over the place.
     
    Kay Schluehr, Jan 5, 2008
    #1
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.