Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #3842

Input() in Python3

From harrismh777 <harrismh777@charter.net>
Newsgroups comp.lang.python
Subject Input() in Python3
Message-ID <I89sp.39115$yp3.5013@newsfe09.iad> (permalink)
Date 2011-04-22 01:22 -0500

Show all headers | View raw


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

Back to comp.lang.python | Previous | NextNext in thread | Find similar


Thread

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