import multiple modules with same name

Discussion in 'Python' started by Christian Bird, Mar 31, 2008.

  1. Is it possible to import multiple modules with the same name from
    different locations? I'm using two different pieces of software, both
    of which have a module named util.py. I know that I can modify
    sys.path to fix which util gets imported when I do:

    import util

    I'd like to be able to do something like:

    import sys
    sys.path.append("/somedir1/")
    import util as util1
    sys.path.insert(0, "/somedir2/")
    import util as util2

    But it appears that once python imports a module, it will never look
    for a module with the same name again. Is there any way to get around
    this? I'd rather not rename either of the util modules as other
    pieces of software use them (but the others never use both of them of
    course) and I don't want to break them or have multiple copies of the
    code in different named files. I'm appreciative of anyone's ideas.

    -- Chris

    --
    Christian Bird
     
    Christian Bird, Mar 31, 2008
    #1
    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. Remy Cool
    Replies:
    1
    Views:
    448
    Remy Cool
    Aug 27, 2003
  2. plb
    Replies:
    0
    Views:
    416
  3. plb
    Replies:
    0
    Views:
    334
  4. Amit Khemka

    Import: Multiple modules with same name

    Amit Khemka, Jun 30, 2006, in forum: Python
    Replies:
    0
    Views:
    288
    Amit Khemka
    Jun 30, 2006
  5. Joel Hedlund
    Replies:
    2
    Views:
    553
    Joel Hedlund
    Nov 11, 2006
Loading...

Share This Page