Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #3922
| Date | 2011-04-23 12:33 -0700 |
|---|---|
| From | Westley Martínez <anikom15@gmail.com> |
| Subject | Re: Input() in Python3 |
| References | <I89sp.39115$yp3.5013@newsfe09.iad> <BANLkTimJ3ZXNK_0jk_yeinmUNo8s1aQfSw@mail.gmail.com> <mailman.746.1303480346.9059.python-list@python.org> <ios24t$k72$1@speranza.aioe.org> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.782.1303587241.9059.python-list@python.org> (permalink) |
On Fri, Apr 22, 2011 at 10:08:20AM -0400, Mel wrote:
> 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.
>
What?
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