[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Noob raw_input question

Abigail

2/24/2010 5:39:00 PM

Yesterday I downloaded and installed Python 3.1 and working through some
examples but I have hit a problem

>>> a = raw_input("Enter a number" )
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
a = raw_input("Enter a number" )
NameError: name 'raw_input' is not defined>>>a = raw_input("Enter a number
")

What am I doing wrong?


5 Answers

Chris Rebert

2/24/2010 6:16:00 PM

0

On Wed, Feb 24, 2010 at 9:39 AM, Abigail <spam@removethis.btinternet.com> wrote:
> Yesterday I downloaded and installed Python 3.1 and working through some
> examples but I have hit a problem
>
>>>> a = raw_input("Enter a number" )
> Traceback (most recent call last):
>  File "<pyshell#6>", line 1, in <module>
>    a = raw_input("Enter a number" )
> NameError: name 'raw_input' is not defined>>>a = raw_input("Enter a number
> ")
>
> What am I doing wrong?

raw_input() got renamed to just input().
Please read the 3.x transition docs at
http://docs.python.org/3.1/whatsne...

Cheers,
Chris
--
http://blog.re...

Robert Kern

2/24/2010 6:21:00 PM

0

On 2010-02-24 11:39 AM, Abigail wrote:
> Yesterday I downloaded and installed Python 3.1 and working through some
> examples but I have hit a problem
>
>>>> a = raw_input("Enter a number" )
> Traceback (most recent call last):
> File "<pyshell#6>", line 1, in<module>
> a = raw_input("Enter a number" )
> NameError: name 'raw_input' is not defined>>>a = raw_input("Enter a number
> ")
>
> What am I doing wrong?

Python 3 changed the name of raw_input() to input() (and the old input() method
that evaluates the string was simply thrown out as being redundant and unsafe).

http://docs.python.org/dev/3.0/whatsne...

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

John Posner

2/24/2010 6:29:00 PM

0

On 2/24/2010 12:39 PM, Abigail wrote:
> Yesterday I downloaded and installed Python 3.1 and working through some
> examples but I have hit a problem
>
>>>> a = raw_input("Enter a number" )
> Traceback (most recent call last):
> File "<pyshell#6>", line 1, in<module>
> a = raw_input("Enter a number" )
> NameError: name 'raw_input' is not defined>>>a = raw_input("Enter a number
> ")
>
> What am I doing wrong?
>
>

The Python 2 built-in function "raw_input" has been renamed to "input"
in Python 3. You'll probably run into this, too:

Python 2: print "hello, world"
Python 3: print("hello, world")

You might want to install Python 2 if you're working your way through a
tutorial that's targeted at that "generation" of the language.

-John


Steve Holden

2/24/2010 6:33:00 PM

0

Abigail wrote:
> Yesterday I downloaded and installed Python 3.1 and working through some
> examples but I have hit a problem
>
>>>> a = raw_input("Enter a number" )
> Traceback (most recent call last):
> File "<pyshell#6>", line 1, in <module>
> a = raw_input("Enter a number" )
> NameError: name 'raw_input' is not defined>>>a = raw_input("Enter a number
> ")
>
> What am I doing wrong?
>
>
In Python 3 raw_input() is now simply called input()

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
PyCon is coming! Atlanta, Feb 2010 http://us....
Holden Web LLC http://www.hold...
UPCOMING EVENTS: http://holdenweb.event...

Abigail

2/24/2010 6:33:00 PM

0

Thank You