question on "input"
Hi, I want to accept the user's answer yes or no. If I do this: answer = input('y or n?') and type y on the keyboard, python complains Traceback (most recent call last): File "", line 1, in ? File "", line 0, in ? NameError: name 'y' is not defined It seems like input only accepts numerals, or strings with quotes. Need solutions, thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: question on "input"
On 12 Jul 2005 07:31:47 -0700, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Hi, > > I want to accept the user's answer yes or no. > If I do this: > > answer = input('y or n?') Use raw_input instead: >>> answer = raw_input("y or n?") y or n?y >>> answer 'y' Check out the documentation of both functions at http://docs.python.org/lib/built-in-funcs.html for more details. Peace Bill Mill -- http://mail.python.org/mailman/listinfo/python-list
Re: question on "input"
Use raw_input instead. It returns a string of whatever was typed. Input expects a valid python expression. -- http://mail.python.org/mailman/listinfo/python-list
Who uses input()? [was Re: question on "input"]
Devan L wrote: > Use raw_input instead. It returns a string of whatever was typed. Input > expects a valid python expression. Who actually uses this? It's equivalent to eval(raw_input(prompt)) but causes a lot of newbie confusion. Python-dev archives revealed that someone tried to get this deprecated but Guido disagreed. -- Michael Hoffman -- http://mail.python.org/mailman/listinfo/python-list
Re: Who uses input()? [was Re: question on "input"]
On Thursday 14 July 2005 07:00 am, Michael Hoffman wrote: > Devan L wrote: > > Use raw_input instead. It returns a string of whatever was typed. Input > > expects a valid python expression. > > Who actually uses this? It's equivalent to eval(raw_input(prompt)) but > causes a lot of newbie confusion. Python-dev archives revealed that > someone tried to get this deprecated but Guido disagreed. I don't think it should disappear, but it *does* seem more sensible for "raw_input" to be called "input" (or "readstring" or some such thing) and "input" to vanish into greater obscurity as "eval_input" or something. Unfortunately, that would break code if anything relied on "input", so I guess that would be a Py3K idea, and maybe the whole I/O concept will be rethought then (if the "print" statement is going to go away, anyway). -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Who uses input()? [was Re: question on "input"]
On 15/07/05, Terry Hancock <[EMAIL PROTECTED]> wrote: > On Thursday 14 July 2005 07:00 am, Michael Hoffman wrote: > > Devan L wrote: > > > Use raw_input instead. It returns a string of whatever was typed. Input > > > expects a valid python expression. > > > > Who actually uses this? It's equivalent to eval(raw_input(prompt)) but > > causes a lot of newbie confusion. Python-dev archives revealed that > > someone tried to get this deprecated but Guido disagreed. > > I don't think it should disappear, but it *does* seem more sensible for > "raw_input" to be called "input" (or "readstring" or some such thing) and > "input" to vanish into greater obscurity as "eval_input" or something. > > Unfortunately, that would break code if anything relied on "input", so I > guess that would be a Py3K idea, and maybe the whole I/O concept > will be rethought then (if the "print" statement is going to go away, > anyway). I don't see as "break input() using code" -> "not until py3k" as a logical cause/effect. No one should be using input() anyway, the only place it's at-all appropriate is in a python tutorial, with the 'guess the number' game. -- Stephen Thorne Development Engineer -- http://mail.python.org/mailman/listinfo/python-list
Re: Who uses input()? [was Re: question on "input"]
I use input() all the time. I know many people say it ain't safe, but whose going to use it to crash their own comp? Only an insane person would, or a criminal trying to cover his/her tracks. Sorry if I waded into the debate, but this debate originated from one of my posts. Nathan Pinno - Original Message - From: "Stephen Thorne" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Cc: Sent: Sunday, July 17, 2005 11:12 PM Subject: Re: Who uses input()? [was Re: question on "input"] > On 15/07/05, Terry Hancock <[EMAIL PROTECTED]> wrote: >> On Thursday 14 July 2005 07:00 am, Michael Hoffman wrote: >> > Devan L wrote: >> > > Use raw_input instead. It returns a string of whatever was typed. Input >> > > expects a valid python expression. >> > >> > Who actually uses this? It's equivalent to eval(raw_input(prompt)) but >> > causes a lot of newbie confusion. Python-dev archives revealed that >> > someone tried to get this deprecated but Guido disagreed. >> >> I don't think it should disappear, but it *does* seem more sensible for >> "raw_input" to be called "input" (or "readstring" or some such thing) and >> "input" to vanish into greater obscurity as "eval_input" or something. >> >> Unfortunately, that would break code if anything relied on "input", so I >> guess that would be a Py3K idea, and maybe the whole I/O concept >> will be rethought then (if the "print" statement is going to go away, >> anyway). > > I don't see as "break input() using code" -> "not until py3k" as a > logical cause/effect. No one should be using input() anyway, the only > place it's at-all appropriate is in a python tutorial, with the 'guess > the number' game. > > -- > Stephen Thorne > Development Engineer > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: Who uses input()? [was Re: question on "input"]
"Nathan Pinno" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I use input() all the time. I know many people say it ain't safe, but > whose going to use it to crash their own comp? Only an insane person > would, This is usage Guido intended it for, not for production apps distributed to world. -- http://mail.python.org/mailman/listinfo/python-list