471,086 Members | 853 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,086 software developers and data experts.

import multiple modules with same name

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
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
Mar 31 '08 #1
0 1401

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

16 posts views Thread by Manlio Perillo | last post: by
reply views Thread by John Roth | last post: by
4 posts views Thread by Torsten Bronger | last post: by
4 posts views Thread by Nicolas Fleury | last post: by
5 posts views Thread by passion_to_be_free | last post: by
23 posts views Thread by Shane Hathaway | last post: by
reply views Thread by Amit Khemka | last post: by
49 posts views Thread by Martin Unsal | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.