[Tutor] Anyone fancy giving me some tips and an expert opinion??
Kent Johnson
kent37 at tds.net
Fri Feb 8 03:15:50 CET 2008
Damian Archer wrote:
> # User inputs numbers to compare, z is for the index counter
> x = input("Enter a number between 1 and 0: ")
> y = input("Enter a second number between 1 and 0: ")
We generally discourage the use of input(), it is (arguably) a security
hole -
http://www.wellho.net/mouth/956_Python-security-trouble-with-input.html
and a rather contentious discussion on this very list -
http://mail.python.org/pipermail/tutor/2007-August/056328.html
- and it doesn't validate the input. A better way to write this would be
x = float(raw_input("Enter a number between 1 and 0: "))
y = float(raw_input("Enter a second number between 1 and 0: "))
which is safer and guarantees that x and y are floating point numbers.
Kent
More information about the Tutor
mailing list