Newbie: Changing a string to a class attribute.

Peter Abel PeterAbel at gmx.net
Sat Sep 27 00:17:49 CEST 2003


Jeff Epler <jepler at unpythonic.net> wrote in message news:<mailman.1064588380.4062.python-list at python.org>...
> On Thu, Sep 25, 2003 at 01:27:24PM -0700, Peter Abel wrote:
> > >>> def exec_method(object, method):
> > ... 	eval('object.'+method) ()
> 
> Why not write
>     def exec_method(object, method):
>         getattr(object, method)()
> no nasty 'eval' there, thank goodness.
> 
> Jeff

It's okay.
Seems to be clearer.

Peter




More information about the Python-list mailing list