Importing a module, using a variable name?

Gordon McMillan gmcm at
Fri Mar 10 05:20:34 CET 2000

Benjamin Schollnick wrote:
> 	Is it possible to import a module, via a variable?  I've tried it 
> myself,
> 	and it doesn't seem possible.  Is there another "less obvious" method
> 	that would allow me to do roughly the same thing?
> 	Here's the example I tried:
> 		module_to_import = "test"
> 		import module_to_import

mod = __import__(module_to_import)

- Gordon

More information about the Python-list mailing list