Input() in Python3

harrismh777 harrismh777 at
Fri Apr 22 08:22:32 CEST 2011

My interactive scripts are giving errors on the input(). I discovered 
another fairly significant change in Python3, as discussed in PEP 3111.

I was a little flabbergasted to discover that input() was proposed to be 
removed 'totally' from 3000. Of course I agree with PEP 3111 and am 
thankful that input() is still a built-in.  doh.

The problem is that the behavior was significantly changed, again, 
causing existing code to break un-necessarily. So, input() used to be 
equivalent to:

    eval(raw_input("prompt>")) --> value

now we get this for input():

    raw_input("prompt>") --> string

I'm not whining or anything, just wondering why? Could someone enlighten 
me please?

Anyway, it looks like the best fix for 2.x --> 3.x  code changes:

change:    a = input("enter a number > ")

to:        a = eval(input("enter a number > "))

Again, this is just another example where leaving the advertised 
interface alone would have made more sense... unless of course, I'm 
missing something important here.

kind regards,
m harris

More information about the Python-list mailing list