[Tutor] name is not defined error (fwd)
Danny Yoo
dyoo at hkn.eecs.berkeley.edu
Sun Oct 29 18:43:04 CET 2006
---------- Forwarded message ----------
Date: Sun, 29 Oct 2006 12:33:58 -0500
From: Kristinn Didriksson <kdidriksson at gmail.com>
To: Danny Yoo <dyoo at hkn.eecs.berkeley.edu>
Subject: Re: [Tutor] name is not defined error
Hi Danny,
Thanks :)
The program works now. I'll take a look at those threads.
Here is what the book says " This function (eval) takes any string and
evaluates it as if it were a Python expression." I took that to mean that it
would turn a sting into an integer. Oops.
it is a little confusing to get started, but lots of practice will change that.
Thanks for your help.
Regards,
Kristinn
On Oct 29, 2006, at 12:15 PM, Danny Yoo wrote:
>
>
>> 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