Newbie: Changing a string to a class attribute.

Jeff Epler jepler at unpythonic.net
Fri Sep 26 16:58:33 CEST 2003


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





More information about the Python-list mailing list