doubt with importing module, given module name

Pradnyesh Sawant spradml at gmail.com
Mon Apr 9 13:22:37 EDT 2007


Hello,
I have a string which in reality is the name of a module to be
imported. The name of the class contained in the module also has the
same (although with different capitalization). My requirement is to
import the module, and also create an instance of the class. eg:

str = "module"             #name of module is "module.py"
cls = str.capitalize()      #name of class is "Module"
inst = cls()                   #create an instance of class "Module"

how do i do this?

Thanks a lot in advance



More information about the Python-list mailing list