Import: Multiple modules with same name

Discussion in 'Python' started by Amit Khemka, Jun 30, 2006.

  1. Amit Khemka

    Amit Khemka Guest

    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.
     
    Amit Khemka, Jun 30, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Remy Cool
    Replies:
    1
    Views:
    433
    Remy Cool
    Aug 27, 2003
  2. plb
    Replies:
    0
    Views:
    400
  3. plb
    Replies:
    0
    Views:
    318
  4. Joel Hedlund
    Replies:
    2
    Views:
    512
    Joel Hedlund
    Nov 11, 2006
  5. Christian Bird

    import multiple modules with same name

    Christian Bird, Mar 31, 2008, in forum: Python
    Replies:
    0
    Views:
    285
    Christian Bird
    Mar 31, 2008
Loading...

Share This Page