Import: Multiple modules with same name



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.

--
----
Amit Khemka -- onyomo.com
Home Page: www.cse.iitd.ernet.in/~csd00377
Endless the world's turn, endless the sun's Spinning, Endless the quest;
I turn again, back to my own beginning, And here, find rest.
.



Relevant Pages

  • Re: Storing of folder structure in SQL DB
    ... On 4/5/07, Amit Khemka wrote: ... for path, dirs, files in os.walk: ... It stores ids as a tuple ... Endless the world's turn, endless the sun's Spinning, Endless the quest; ...
    (comp.lang.python)
  • Re: all ip addresses of machines in the local network
    ... On 8/24/06, Amit Khemka wrote: ... > database onto different machines residing in the same network. ... I expect that you would know the IP range for your network. ... Endless the world's turn, endless the sun's Spinning, Endless the quest; ...
    (comp.lang.python)
  • Re: for statement on empty iterable
    ... That doesn't crash or anything like that, ... which can cause confusion in some situations. ... Amit Khemka ... Endless the world's turn, endless the sun's Spinning, Endless the quest; ...
    (comp.lang.python)
  • Re: reading files in small chunks?
    ... I wanted to know why it is more efficient to read a file in smaller chunks ( ... search engine. ... Amit Khemka -- onyomo.com ... Endless the world's turn, endless the sun's Spinning, Endless the quest; ...
    (comp.lang.python)
  • Solution..
    ... Before anyone spends time on this, I stumbled over the answer after endless ... debugging, it turns out the Command field in the Switchboard Items table was ...
    (microsoft.public.access.forms)