imp module

Dave Kuhlman dkuhlman at rexx.com
Thu Sep 28 14:33:05 EDT 2000


Does the following do what you want?

>>> foo = 'aaa'
>>> bar = 'bbb'
>>> cmd = 'import %s.%s' % (foo, bar)
>>> exec(cmd)

  - Dave


Magnus Heino <magnus.heino at rivermen.se> wrote:
> 
> 
> Hi.
> 
> I want to import a module that dont know the name of then coding.
> 
> Example:
> 
> To import module bar in directory foo I could do:
> 
> import foo.bar
> 
> However, since I dont know the names foo and bar, I cant do it that way.
> Therefore I had a look at the imp module, and tried something like this:
> 
> import imp
> fp, pathname, desc = imp.find_module('bar' ['foo'])
> 
> m = imp.load_module(bar, fp, pathname, desc)
> 
> What should I now do with m to get foo.bar into the current namespace?
> 
> /Magnus
> 

-- 
Dave Kuhlman
dkuhlman at rexx.com



More information about the Python-list mailing list