select a class in execution time

Duncan Booth duncan at NOSPAMrcp.co.uk
Mon Apr 7 11:24:08 EDT 2003


cybersamurai at mac.com wrote in news:mailman.1049724192.1994.python-
list at python.org:

> have some like that on Python?
> 
> Object x = Class.forName( "mypackage.TheClass" ).newInstace();
> (this is a java code)

    def find_class(module, name):
        __import__(module)
        mod = sys.modules[module]
        klass = getattr(mod, name)
        return klass


-- 
Duncan Booth                                             duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?




More information about the Python-list mailing list