Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > import multiple modules with same name

Reply
Thread Tools

import multiple modules with same name

 
 
Christian Bird
Guest
Posts: n/a
 
      03-31-2008
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Import: Multiple modules with same name Amit Khemka Python 0 06-30-2006 06:46 AM
Handling import conflicts when module has the same name as a library module that it needs to import? plb Python 0 02-08-2005 01:08 PM
Handling import conflicts when module has the same name as a library module that it needs to import? plb Python 0 02-08-2005 01:01 PM
imputils - import problem modules from sys.modules Remy Cool Python 1 08-27-2003 02:25 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57