import class from string

Mariano DAngelo marianoa.dangelo at gmail.com
Wed Jul 4 16:27:29 EDT 2012


Hi I'm trying to create a class from a string.... 
This is my code, but is not working....

'myshop.models.base'
module_name, class_name = model.rsplit(".", 1)
module = importlib.import_module(module_name)
class_ = getattr(module, class_name)()


Anyone know what I'm doing wrong.... or another way?

thanks



More information about the Python-list mailing list