[Tutor] eval use (directly by interpreter vs with in a script)

Albert-Jan Roskam fomcl at yahoo.com
Mon Nov 3 18:33:18 CET 2014

>Real question is what you're trying to do.  eval() and exec() are to be 
>avoided if possible, so the solutions are not necessarily the easiest.

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.

More information about the Tutor mailing list