Import: Multiple modules with same name

A

Amit Khemka

Hello All,

I have multiple modules with same name in different directories (well
I guess thats may not be a good practise, but i needed it for
debugging and working with various versions). Now how do I import a
module with specifying a path.

Few minutes of googling suggested:

import ihooks
import os

def my_import(filename):
loader = ihooks.BasicModuleLoader()
path, file = os.path.split(filename)
name, ext = os.path.splitext(file)
module = loader.find_module_in_dir(name, path)
if not module:
raise ImportError, name
module = loader.load_module(name, module)
return module


But It looked like an overkill, Is there a more elegant and better way
of doing it ?

Thanks in advance,

cheers,
amit.

--
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top