Re: "dynamical" importing



Try:

userModule = _importModule( pathToModule )

def _importModule( moduleName ):
   modName = __import__ ( moduleName )
   modComponents = moduleName.split( '.' )
   for indivComp in modComponents[ 1: ]:
       modName = getattr( modName, indivComp )

   return modName

HTH,

J

Joerg Schuster wrote:

Hello,

I need to import modules from user defined paths. I.e. I want to do
something
like:

module_dir = sys.argv[1]

my_path = os.path.join(module_dir, 'bin', 'my_module')

from my_path import my_object

Obviously, it doesn't work this way. How would it work?

Jörg Schuster




.