Loading a class the name of which is only known runtime

Mads Orbesen Troest mads at troest.NEVERMORE.dk
Tue Apr 8 14:08:58 EDT 2003


On Tue, 08 Apr 2003 17:24:15 GMT, Tim Gahnström /Bladerman wrote:

Hi Tim, and thanks for your response.

> If this is what ou are asking for it is certanly possible.
> 
> if test:
>     import modul1
>     a=class1()

Actually, what I am looking for is more alone the lines of:

	moduleToImport = "SomeModule" # <- Retrieved as CGI argument
	classToInstantiate = "SomeClass" # <- Retrieved as CGI argument

	import moduleToImport
	someInstance = classToInstantiate()

Of course, the above does not work. But is there any way to achieve what I 
outline here?

Regards,
   /\/\\ads Orbesen Troest




More information about the Python-list mailing list