[Tutor] name is not defined error

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Sun Oct 29 18:15:11 CET 2006



> It is my understanding that eval turns a string into a number and then I 
> can do math operations on it.

Hi Kristinn,

No, no, that's not what it does.  *grin*

Where did you read about eval() from?  If you saw it in a beginner's 
tutorial, tell us who the guilty party is so we can knock some sense into 
that tutorial.

Don't use eval(): it's "unsafe" in the sense that it does something much 
more than what one might expect. I won't say too much more about it at the 
moment, but if you're interested, see the threads:

     http://mail.python.org/pipermail/tutor/2001-September/008967.html
     http://mail.python.org/pipermail/tutor/2004-December/033828.html

for examples.  Again, I have to say this again: don't use eval() unless 
you really know what you're doing.


Anyway, I think you're looking for the ord() function:

     http://docs.python.org/lib/built-in-funcs.html#l2h-55

Its inverse is the chr() function:

     http://docs.python.org/lib/built-in-funcs.html#l2h-15

Good luck!


More information about the Tutor mailing list