Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #3870
| From | Mel <mwilson@the-wire.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Input() in Python3 |
| Followup-To | comp.lang.python |
| Date | 2011-04-22 10:08 -0400 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <ios24t$k72$1@speranza.aioe.org> (permalink) |
| References | <I89sp.39115$yp3.5013@newsfe09.iad> <BANLkTimJ3ZXNK_0jk_yeinmUNo8s1aQfSw@mail.gmail.com> <mailman.746.1303480346.9059.python-list@python.org> |
Followups directed to: comp.lang.python
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 <type 'exceptions.RuntimeError'> ignored
Exception RuntimeError: 'maximum recursion depth exceeded while calling a
Python object' in <type 'exceptions.RuntimeError'> ignored
Error in sys.excepthook:
RuntimeError: maximum recursion depth exceeded
Original exception was:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
RuntimeError: maximum recursion depth exceeded while calling a Python object
>>> int (0)
Exception RuntimeError: 'maximum recursion depth exceeded while calling a
Python object' in <type 'exceptions.RuntimeError'> ignored
Exception RuntimeError: 'maximum recursion depth exceeded while calling a
Python object' in <type 'exceptions.RuntimeError'> ignored
Error in sys.excepthook:
RuntimeError: maximum recursion depth exceeded
Original exception was:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
RuntimeError: maximum recursion depth exceeded while calling a Python object
>>>
Mel.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar
Input() in Python3 harrismh777 <harrismh777@charter.net> - 2011-04-22 01:22 -0500
Re: Input() in Python3 Chris Angelico <rosuav@gmail.com> - 2011-04-22 16:49 +1000
Re: Input() in Python3 Chris Angelico <rosuav@gmail.com> - 2011-04-22 16:50 +1000
Re: Input() in Python3 Chris Rebert <clp2@rebertia.com> - 2011-04-22 00:46 -0700
Re: Input() in Python3 harrismh777 <harrismh777@charter.net> - 2011-04-23 20:03 -0500
Re: Input() in Python3 Westley Martínez <anikom15@gmail.com> - 2011-04-22 06:52 -0700
Re: Input() in Python3 Mel <mwilson@the-wire.com> - 2011-04-22 10:08 -0400
Re: Input() in Python3 Chris Angelico <rosuav@gmail.com> - 2011-04-23 06:25 +1000
Re: Input() in Python3 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-04-22 23:55 +0000
Re: Input() in Python3 Chris Angelico <rosuav@gmail.com> - 2011-04-23 10:07 +1000
Re: Input() in Python3 Westley Martínez <anikom15@gmail.com> - 2011-04-23 12:33 -0700
Re: Input() in Python3 Mel <mwilson@the-wire.com> - 2011-04-25 12:50 -0400
csiph-web