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.
--
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.
--