<br><br><div class="gmail_quote">On Mon Nov 03 2014 at 10:48:29 AM Danny Yoo <<a href="mailto:dyoo@hashcollision.org">dyoo@hashcollision.org</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_quote">On Mon Nov 03 2014 at 10:04:41 AM Alan Gauld <<a href="mailto:alan.gauld@btinternet.com" target="_blank">alan.gauld@btinternet.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 03/11/14 17:33, Albert-Jan Roskam wrote:<br>
<br>
> I sometimes do something like<br>
> ifelse = "'teddybear' if bmi > 30 else 'skinny'"<br>
> weightcats = [eval(ifelse) for bmi in bmis]<br>
><br>
> Would this also be a *bad* use of eval? It can be avoided, but this is so concise.<br></blockquote></div></blockquote><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"></blockquote></div><div class="gmail_quote"><div>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.</div></div></blockquote><div><br></div><div><br></div><div>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.</div><div><br></div><div>In any case, the other comments still stand.  You want to use functions for cases like the above.</div></div>