missive at frontiernet.net
Wed Apr 2 01:03:05 CEST 2003
In article <b6d191$j7s$1 at news-reader12.wanadoo.fr>, Salvatore wrote:
> I would like to create an instance of class
> from the string name of the class
> class Foo:
> classname = 'Foo'
> instance = create_instance('Foo')
I think it depends on which namespace the class lives in,
and where you want to get at it from.
In the interactive interpreter, you might do:
instance = locals()['Foo']()
If the class lived in a module, say FooMod.py you could do:
instance = getattr(FooMod, 'Foo')()
More information about the Python-list