imputils - import problem modules from sys.modules

Discussion in 'Python' started by Remy Cool, Aug 21, 2003.

  1. Remy Cool

    Remy Cool Guest

    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.ImportManager().install()
    sys.path.insert(0, DictImporter(archive))
    sys.path.insert(0, imputil.BuiltinImporter())

    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, Aug 21, 2003
    #1
    1. Advertising

  2. Remy Cool

    Remy Cool Guest

    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

    > 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.ImportManager().install()
    > sys.path.insert(0, DictImporter(archive))
    > sys.path.insert(0, imputil.BuiltinImporter())
    >
    > 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, Aug 27, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ronald Meier
    Replies:
    2
    Views:
    1,542
    Keith S.
    Oct 21, 2003
  2. Roman Neuhauser
    Replies:
    0
    Views:
    677
    Roman Neuhauser
    Apr 4, 2005
  3. Replies:
    2
    Views:
    680
    velle
    Jan 5, 2006
  4. gen_tricomi
    Replies:
    2
    Views:
    787
    gen_tricomi
    May 23, 2006
  5. lkcl
    Replies:
    6
    Views:
    352
Loading...

Share This Page