Importing a module, using a variable name?

Gordon McMillan gmcm at hypernet.com
Thu Mar 9 23:20:34 EST 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