[Tutor] Re: Suggestions for cleaner code
Raymond Hettinger
python@rcn.com
Tue Jul 8 21:25:03 2003
> >Can I ask why 'input' is frowned upon? I noticed that in 'Core Python
> >Programming' the method is as below, namely "int(raw_input())", but in
> >the 'Non-programmer's' tutorial, 'input()' is used. Just curious.
It depends on who is doing the frowning. Guido rather likes input()
and finds it helpful so that a user can input something like:
10 * 20
or
current_count + 1
For production code, it presents a security risk since untrusted
input is passed directly to eval(). So, your innocuous:
f = input('how many friends do you have?')
will allow a rather unhelpful response like:
os.unlink('/profile.sh')
Raymond Hettinger