selecting a class in execution time

cybersamurai at mac.com cybersamurai at mac.com
Mon Apr 7 15:56:56 EDT 2003


Thanks about your help

I am developing a way to describe a application in XML language. De 
idea is define only the data and your type, using a engine in execution 
time to create a functionality of some application.

take a look in this diagram to get the idea.
in this idea is only needed create a green file to make a application
http://homepage.mac.com/cybersamurai/public/model2.jpg
http://homepage.mac.com/cybersamurai/public/datamodel.jpg
http://homepage.mac.com/cybersamurai/public/data_definition.html

On segunda-feira, 7 abr, 2003, at 14:23 America/Sao_Paulo, Brian 
Quinlan wrote:

> I'd be nice to know the why of this to suggest the best idiom.
>
>> Object x = Class.forName( "mypackage.TheClass" ).newInstace();
>
> x = getattr(__import__("mypackage"), "TheClass")()
>
> The last set of parens is the argument list for TheClass' constructor.
>
> If you know the name of the package at compile time then:
>
> import mypackage
> x = getattr(mypackage, "TheClass")()
>
> Cheers,
> Brian
>






More information about the Python-list mailing list