Creating instance

Salvatore salvatore.didio at wanadoo.fr
Wed Apr 2 00:51:37 CEST 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