Creating instance

Salvatore salvatore.didio at wanadoo.fr
Tue Apr 1 17:51:37 EST 2003


"Syver Enstad" <syver-en+usenet at online.no> a écrit dans le message de news:
u3cl17sfv.fsf at online.no...
> Salvatore <salvatore at wanadoo.fr> writes:
>
> > Hello,
> >
> > I would like to create an instance of class
> > from the string name of the class
> >
> > class Foo:
> > pass
> >
> > classname = 'Foo'
>
> Does this suit you?
>
> instance = eval(classname)()


The beauty is in the simplicity
Thank you very much Syver :o)









More information about the Python-list mailing list