<p><br>
On Apr 22, 2011 10:12 AM, "Mel" <<a href="mailto:mwilson@the-wire.com">mwilson@the-wire.com</a>> wrote:<br>
><br>
> Westley Martínez wrote:<br>
> > On Fri, Apr 22, 2011 at 04:49:19PM +1000, Chris Angelico wrote:<br>
><br>
> >> Uhhhh.... NO. NO NO NO. What if someone enters "os.exit()" as their<br>
> >> number? You shouldn't eval() unchecked user input!<br>
> >><br>
> >> Chris Angelico<br>
> ><br>
> > Right, there's no way to check you're getting a number, however using:<br>
> ><br>
> > a = int(input('enter a number > ')) # use float() for floats<br>
> ><br>
> > will raise an exception if it can't convert the string.<br>
><br>
> But sys.exit() doesn't return a string.  My fave is<br>
><br>
> Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56)<br>
> [GCC 4.4.3] on linux2<br>
> Type "help", "copyright", "credits" or "license" for more information.<br>
> >>> import sys<br>
> >>> a = int (input ('enter a number >'))<br>
> enter a number >sys.setrecursionlimit(1)<br>
> Exception RuntimeError: 'maximum recursion depth exceeded while calling a<br>
> Python object' in <type 'exceptions.RuntimeError'> ignored<br>
> Exception RuntimeError: 'maximum recursion depth exceeded while calling a<br>
> Python object' in <type 'exceptions.RuntimeError'> ignored<br>
> Error in sys.excepthook:<br>
> RuntimeError: maximum recursion depth exceeded<br>
><br>
> Original exception was:<br>
> Traceback (most recent call last):<br>
>  File "<stdin>", line 1, in <module><br>
> RuntimeError: maximum recursion depth exceeded while calling a Python object<br>
> >>> int (0)<br>
> Exception RuntimeError: 'maximum recursion depth exceeded while calling a<br>
> Python object' in <type 'exceptions.RuntimeError'> ignored<br>
> Exception RuntimeError: 'maximum recursion depth exceeded while calling a<br>
> Python object' in <type 'exceptions.RuntimeError'> ignored<br>
> Error in sys.excepthook:<br>
> RuntimeError: maximum recursion depth exceeded<br>
><br>
> Original exception was:<br>
> Traceback (most recent call last):<br>
>  File "<stdin>", line 1, in <module><br>
> RuntimeError: maximum recursion depth exceeded while calling a Python object<br>
> >>><br>
><br>
><br>
>        Mel.<br>
><br></p>
<p>We're talking about python 3, not python 2. If you're using python 2, the equivalent code would be int(raw_input()) and that isn't vulnerable to this sort of thing.<br>
> --<br>
> <a href="http://mail.python.org/mailman/listinfo/python-list">http://mail.python.org/mailman/listinfo/python-list</a><br>
</p>