imputils - import problem modules from sys.modules

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Remy Cool

    imputils - import problem modules from sys.modules

    Hello,

    I've created an archive import class (with the help of importers.py from the
    python /demo/imputil dir) which imports packages and modules from a
    dictionary. So far so good.

    The problem is that every import statement after the code:

    imputil.ImportM anager().instal l()
    sys.path.insert (0, DictImporter(ar chive))
    sys.path.insert (0, imputil.Builtin Importer())

    tries to import from the dictionary and doesn't use the modules that were
    imported before.

    For example, I would like to use os in a module that's stored in the
    dictionary. The import os statement tries to import os from the dictionary
    and does not 'use' the already imported os module that is in the modules
    list.

    Is it possible to get access to both, already loaded modules in the modules
    list and modules in the dictionary?

    Regards,
    Remy Cool
  • Remy Cool

    #2
    Re: imputils - import problem modules from sys.modules

    Problem solved!!!

    Switched to python 2.3 and created a class using the brand new
    sys.path_hooks.

    See python PEP302 for more info on this subject.

    Remy
    [color=blue]
    > Hello,
    >
    > I've created an archive import class (with the help of importers.py from
    > the python /demo/imputil dir) which imports packages and modules from a
    > dictionary. So far so good.
    >
    > The problem is that every import statement after the code:
    >
    > imputil.ImportM anager().instal l()
    > sys.path.insert (0, DictImporter(ar chive))
    > sys.path.insert (0, imputil.Builtin Importer())
    >
    > tries to import from the dictionary and doesn't use the modules that were
    > imported before.
    >
    > For example, I would like to use os in a module that's stored in the
    > dictionary. The import os statement tries to import os from the dictionary
    > and does not 'use' the already imported os module that is in the modules
    > list.
    >
    > Is it possible to get access to both, already loaded modules in the
    > modules list and modules in the dictionary?
    >
    > Regards,
    > Remy Cool[/color]

    Comment

    Working...