Using exec

Kerim Borchaev warkid at storm.ru
Wed Aug 29 08:14:27 EDT 2001


I need to reference an object's method given a string representation
of it's name. Now I do it like this:

exec( "c."+MethonName+"()" )

or if I need to create an instance of class named ClassName I do this:

exec( "inst="+ClassName+"()" )

but it seems ugly to me.

Is it the right thing to do it this way?

Thanks in advance,
 Kerim                          mailto:warkid at storm.ru






More information about the Python-list mailing list