imp module

Magnus Heino magnus.heino at rivermen.se
Thu Sep 28 09:22:09 EDT 2000


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




More information about the Python-list mailing list