Error evaluating numbers starting in zero

Greg Ewing greg at cosc.canterbury.ac.nz
Tue Dec 19 05:08:24 CET 2000


Mike Brenner wrote:
> 
> So, that may also explain the failure with
> 
>         i = 08
> 
> the python interpretor must be using EVAL

Actually, it's the other way around -- eval() is
using the Python interpreter! In other words,
eval() evaluates an *expression* (not just a
number!) according to the rules of the Python 
programming language.

> and with reading in numbers,

The input() function uses eval() to evaluate
the string which is read in. If you don't want
that, use raw_input() and process the string
yourself.

Generally it's a bad idea to use eval() or
input() unless you're sure it's *really* what
you want. Most of the time it's massive overkill,
and can even lead to security problems. For
instance, consider that if someone types
"foo()" in response to an input() statement,
it will cause the foo() function IN YOUR PROGRAM
to be called. Or if they typed

   os.unlink("/home/fred/really_important_file.txt")

the consequences could be unpleasant!

-- 
Greg Ewing, Computer Science Dept, University of Canterbury,	  
Christchurch, New Zealand
To get my email address, please visit my web page:	  
http://www.cosc.canterbury.ac.nz/~greg



More information about the Python-list mailing list