Re: import class from string

2012-07-04 Thread Thomas Jollans
On 07/04/2012 10:27 PM, Mariano DAngelo wrote: > Hi I'm trying to create a class from a string > This is my code, but is not working It would be helpful if you posted an error message. Then, we could know what's actually going on. > 'myshop.models.base' > module_name, class_name = model

Re: import class from string

2012-07-04 Thread Steven D'Aprano
On Wed, 04 Jul 2012 13:27:29 -0700, Mariano DAngelo wrote: > 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(m

import class from string

2012-07-04 Thread Mariano DAngelo
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?