Hard to understand 'eval'
Calvin Spealman
ironfroggy at socialserve.com
Sun Jun 15 13:15:25 EDT 2008
The point here is that eval() use is general frowned upon. If you
don't understand it or the alternatives, then you probably don't
understand it well enough to make the call on using it or not.
If you need just look up an attribute where the name of the attribute
is in a variable, use getattr(obj, attribute_name). If you need to
call a method somewhere, you should have both the name of the method
and the list of arguments to call it with, such as getattr(obj,
methname)(a, b, c). Does this make sense?
On Jun 15, 2008, at 5:16 AM, TheSaint wrote:
> On 04:08, domenica 15 giugno 2008 bruno.desthuilliers at gmail.com wrote:
>
>> what's wrong with getattr(cp, nn) ?
>
> The learning curve to get into these programming ways.
> Does gettattr run the snippet passed in?
> Considering that nn is a name of function, which will be called and
> (cfl,
> value) are the parameters to passed to that function.
>
> I'll spend some bit on getattr use.
> --
> Mailsweeper Home : http://it.geocities.com/call_me_not_now/index.html
> --
> http://mail.python.org/mailman/listinfo/python-list
More information about the Python-list
mailing list