On Mon Nov 03 2014 at 10:48:29 AM Danny Yoo <d...@hashcollision.org> wrote:

> On Mon Nov 03 2014 at 10:04:41 AM Alan Gauld <alan.ga...@btinternet.com>
> wrote:
>
>> On 03/11/14 17:33, Albert-Jan Roskam wrote:
>>
>> > I sometimes do something like
>> > ifelse = "'teddybear' if bmi > 30 else 'skinny'"
>> > weightcats = [eval(ifelse) for bmi in bmis]
>> >
>> > Would this also be a *bad* use of eval? It can be avoided, but this is
>> so concise.
>>
>

> Consider if 'bmi' were ever controlled from the outside world.  At the
> very worst, the normal function approach will raise a runtime error, but
> that's it.  In contrast, the eval approach can take over your machine.
>


I should be a bit more careful in saying this.  I should have said:
"Consider if 'ifelse'" were ever controlled from the outside world...".  My
apologies for writing a bit too fast there.

In any case, the other comments still stand.  You want to use functions for
cases like the above.
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to