dynamic class/module use? (like Java's forName)

Alex Hunsley lard at tardis.ed.ac.molar.uk
Sat Jul 17 14:11:16 EDT 2004


Alex Hunsley wrote:

> Does python provide a way to dynamically use modules and/or classes?
> I'm thinking in the vein of Java's Class.forName.
> 
> As a pseudocode example, I'm looking for the following ability:
> 
> 
> classIWantToInstantiate = "packagenamehere.classNameHere"
> 
> anInstanceOfThatClass = makeNewClassFromString(classIWantToInstantiate, 
> parameters[])
> 
> # now anInstanceOfThatClass refers to an instantied
> # packagenamehere.classNameHere object!
> 
> 
> 
> thanks
> alex

Oops.. I goggled but not hard enough obviously! I found my answer on 
google groups:

http://shorterlink.com/?N2HPGU

alex



More information about the Python-list mailing list