[Edu-sig] The fate of raw_input() in Python 3000
Brian Blais
bblais at bryant.edu
Thu Sep 7 21:06:18 CEST 2006
Andre Roberge wrote:
> The following is something I have been pondering for quite a while now
> and am wondering what other people on this list think.
>
> According to PEP 3100
> (http://www.python.org/dev/peps/pep-3100/ )
> raw_input() [as well as input()] is recommended for removal from the
> built-in namespace, to be replaced by sys.stdin.readline().
>
> While I don't think anyone can argue that this removal makes a major
> difference for Python as a programming language, I believe it makes a
> significant difference for using Python as a learning language, adding
> a non-trivial barrier to learning.
>
> Consider the following fake sessions at the interpreter prompt, where
> I use extra parentheses to turn print as a function (as is also
> proposed in Python 3000) - these parentheses can of course be used
> with today's Python.
>
> # First ever program
>>>> print("Hello world!")
> Hello world!
>
> # More complicated example from the first interactive session using
> today's version
>>>> name = raw_input("Enter your name: ")
> Enter your name: Andre
>>>> print("Hello " + name + "!")
> Hello Andre!
>
> # More or less the same example using the proposed changes.
>>>> import sys
>>>> print("Enter your name: ")
> Enter your name:
>>>> name = sys.stdin.readline()
> <-- Andre
>>>> print("Hello " + name + "!")
> Hello Andre!
>
> To explain the above *simple* program to a beginner, we'd need:
> 1. to introduce the import statement
> 2. to introduce the dot notation (something Kirby would be happy with ;-)
>
> Furthermore, the flow is not the same as with today's raw_input().
>
> I don't like it.
>
> While I totally agree with the proposed removal of input() [anything
> using eval() in a hidden way is *bad*], my preference would be to keep
> raw_input()'s functionality, perhaps renaming it to user_input() or
> ask_user().
>
> Thoughts?
>
I think that both should stay, perhaps with different names as suggested by others.
It would seem that eval(stdin.readline()) is far more confusing to beginners. I
don't see input() as dangerous at all, because no serious developer is going to
include it in an end-product, and a beginner would never be in a position to do any
real harm. On the other hand, input() is extremely useful, and concise.
So, is this removal a done-deal, or is there some effective way of reversing the
decision? Does Guido read this list?
bb
--
-----------------
bblais at bryant.edu
http://web.bryant.edu/~bblais
More information about the Edu-sig
mailing list