Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail From: Mel Newsgroups: comp.lang.python Subject: Re: Input() in Python3 Followup-To: comp.lang.python Date: Fri, 22 Apr 2011 10:08:20 -0400 Organization: Aioe.org NNTP Server Lines: 50 Message-ID: References: Reply-To: mwilson@the-wire.com NNTP-Posting-Host: dABE/dRgL5GIkzqwrI5tGA.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Complaints-To: abuse@aioe.org User-Agent: KNode/4.4.8 X-Notice: Filtered by postfilter v. 0.8.2 Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:3870 Westley Martínez wrote: > On Fri, Apr 22, 2011 at 04:49:19PM +1000, Chris Angelico wrote: >> Uhhhh.... NO. NO NO NO. What if someone enters "os.exit()" as their >> number? You shouldn't eval() unchecked user input! >> >> Chris Angelico > > Right, there's no way to check you're getting a number, however using: > > a = int(input('enter a number > ')) # use float() for floats > > will raise an exception if it can't convert the string. But sys.exit() doesn't return a string. My fave is Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> a = int (input ('enter a number >')) enter a number >sys.setrecursionlimit(1) Exception RuntimeError: 'maximum recursion depth exceeded while calling a Python object' in ignored Exception RuntimeError: 'maximum recursion depth exceeded while calling a Python object' in ignored Error in sys.excepthook: RuntimeError: maximum recursion depth exceeded Original exception was: Traceback (most recent call last): File "", line 1, in RuntimeError: maximum recursion depth exceeded while calling a Python object >>> int (0) Exception RuntimeError: 'maximum recursion depth exceeded while calling a Python object' in ignored Exception RuntimeError: 'maximum recursion depth exceeded while calling a Python object' in ignored Error in sys.excepthook: RuntimeError: maximum recursion depth exceeded Original exception was: Traceback (most recent call last): File "", line 1, in RuntimeError: maximum recursion depth exceeded while calling a Python object >>> Mel.