473,394 Members | 1,761 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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 "<stdin>", line 1, in ?
File "<string>", line 0, in ?
NameError: name 'y' is not defined

It seems like input only accepts numerals, or strings with quotes.
Need solutions, thanks.

Jul 21 '05 #1
8 1889
Use raw_input instead. It returns a string of whatever was typed. Input
expects a valid python expression.

Jul 21 '05 #2
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
Jul 21 '05 #3
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

Jul 21 '05 #4
On 15/07/05, Terry Hancock <ha*****@anansispaceworks.com> 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
Jul 21 '05 #5
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" <st************@gmail.com>
To: <ha*****@anansispaceworks.com>
Cc: <py*********@python.org>
Sent: Sunday, July 17, 2005 11:12 PM
Subject: Re: Who uses input()? [was Re: question on "input"]

On 15/07/05, Terry Hancock <ha*****@anansispaceworks.com> 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

Jul 21 '05 #6

"Nathan Pinno" <fa********@hotmail.com> wrote in message
news:BA**********************************@phx.gbl. ..
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.

Jul 21 '05 #7
Hi, folks --

I'm a Python newbie. As you can see from the session copied below, I have the latest version of Python and I've been using the Editor-Shell of the latest version of Boa Constructor while going through some Python tutorials. Everything was working as expected until I started using the raw_input built-in function. There seems to be some unreliable behavior in the Boa Editor - Shell. The input that is entered has the first four bytes dropped before it is stored in the test_string. The problem is inconsistant. It sometimes works fine, then starts dropping the first four characters again. The Idle IDE shell does not exhibit this problem. Any ideas, oh Knights of Ni?? Thanks! :)

-- Jerry Kreps

++++++++++++++++++++++++++++++++++++++++++++++++++

# Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)]
# wxPython 2.6.1.0, Boa Constructor 0.4.4
# Type "copyright", "credits" or "license" for more information.


>>> test_string_01 = raw_input("What is your name?")
What is your name?
<<<
Sir Lancelot
>>> print test_string_01
Lancelot


>>> test_string_02 = raw_input("What is your quest? ")
What is your quest?
<<<
To seek the grail
>>> print test_string_02
eek the grail


>>> test_string_03 = raw_input("What is your favorite color?")
What is your favorite color?
<<<
Orange
>>> print test_string_03
ge


>>> test_string_04 = raw_input("Why are the first four characters dropped? ")
Why are the first four characters dropped?
<<<
Run away!!!
>>> print test_string_04
away!!!
>>>

++++++++++++++++++++++++++++++++++++++++++++
Sep 28 '05 #8
Hi, again.

Since the post before it was over two months ago, I am moving my previous post directly above to a new thread in hope that it will get more notice. I hope this does not break any forum rules.

-- Jerry Kreps :o
Sep 29 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Pete Wilson | last post by:
Hi folks -- The page at http://www.pwilson.net/submit-demo.html will not validate. The validator at http://validator.w3.org tells me I can't have an input inside a form. Would some kind...
5
by: John Oliver | last post by:
I'd like the email produced by FormMail to show a specific From: address rather than postmaster@server.host.name Googling isn't helping me... not sure what to look for :-( -- * John Oliver ...
3
by: Jonathan | last post by:
Hi all: I originally posted this in an HTML forum, but have realized that the solution may (a) require a server-side change or (b) be non-existent. In any case, since the page I'm dealing with is...
1
by: k386 | last post by:
I am having trouble creating a hidden form field, or least having it accessible from getElementById. Rough overview: I am reading an XML file through XMLhttpRequest and outputting each item...
8
by: Ulysse | last post by:
Hello, I need to clean the string like this : string = """ bonne mentalit&eacute; mec!:) \n <br>bon pour info moi je suis un serial posteur arceleur dictateur ^^* \n ...
2
by: Angus | last post by:
I am trying to change the selection in Javascript - but this HTML element is not a standard option control. On the web page it looks like a dropdown list - and you click on the right hand down...
5
by: Maria Sudderman | last post by:
I have a prblem with the "onClick" command. onClick="insert('<a href="URI">', '</a>')"> but this is not correct! why? Maria
4
by: Apple1 | last post by:
Hello! I would like to switch elements on the fly. Dynamicly turn "A" elenent an "input" tag. This is what I tried: <html> <head> <script>
2
by: sixtyfootersdude | last post by:
Good Morning! I am just starting to learn perl and I am somewhat mistifide about when I should do: print("@input"); and when I should do: print(@input)
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.