Input and output are core features of computer programs. Currently,Python provides a simple means of output through the print keywordand two simple means of interactive input through the input()and raw_input() built-in functions.
Python 3.0 will introduce various incompatible changes with previousPython versions (PEP 3100).Among the proposed changes, print will become a built-infunction, print(), while input() and raw_input() would be removed completelyfrom the built-in namespace, requiring importing some module to provideeven the most basic input capability.
This PEP proposes that Python 3.0 retains some simple interactive userinput capability, equivalent to raw_input(), within the built-in namespace.
It was accepted by the BDFL in December 2006[5].
With its easy readability and its support for many programming styles(e.g. procedural, object-oriented, etc.) among others, Python is perhapsthe best computer language to use in introductory programming classes.Simple programs often need to provide information to the user (output)and to obtain information from the user (interactive input).Any computer language intended to be used in an educational setting shouldprovide straightforward methods for both output and interactive input.
Thecurrent proposals for Python 3.0include a simple output pathwayvia a built-in function named print(), but a more complicated method forinput [e.g. via sys.stdin.readline()], one that requires importing an externalmodule. Current versions of Python (pre-3.0) include raw_input() as abuilt-in function. With the availability of such a function, programs thatrequire simple input/output can be written from day one, without requiringdiscussions of importing modules, streams, etc.
Current built-in functions, like input() and raw_input(), are found to beextremely useful in traditional teaching settings. (For more details,see[2] and the discussion that followed.)While the BDFL has clearly stated[3] that input() was not to be kept inPython 3000, he has also stated that he was not against revising thedecision of killing raw_input().
raw_input() provides a simple mean to ask a question and obtain a responsefrom a user. The proposed plans for Python 3.0 would require the replacementof the single statement:
name=raw_input("What is your name?")
by the more complicated:
importsysprint("What is your name?")same=sys.stdin.readline()
However, from the point of view of many Python beginners and educators, theuse of sys.stdin.readline() presents the following problems:
1. Compared to the name “raw_input”, the name “sys.stdin.readline()”is clunky and inelegant.
2. The names “sys” and “stdin” have no meaning for most beginners,who are mainly interested inwhat the function does, and notwherein the package structure it is located. The lack of meaning also makesit difficult to remember:is it “sys.stdin.readline()”, or “ stdin.sys.readline()”?To a programming novice, there is not any obvious reason to preferone over the other. In contrast, functions simple and direct names likeprint, input, and raw_input, and open are easier to remember.
3. The use of “.” notation is unmotivated and confusing to many beginners.For example, it may lead some beginners to think “.” is a standardcharacter that could be used in any identifier.
4. There is an asymmetry with the print function: why is print not calledsys.stdout.print()?
The existingraw_input() function will be renamed toinput().
The Python 2 to 3 conversion tool will replace calls toinput() witheval(input()) andraw_input() withinput().
Withinput() effectively removed from the language,the nameraw_input() makes much less sense and alternatives should beconsidered. The various possibilities mentioned in various forums include:
ask()ask_user()get_string()input()# initially rejected by BDFL, later acceptedprompt()read()user_input()get_response()
While it was initially rejected by the BDFL, it has been suggested that themost direct solution would be to rename “raw_input” to “input” in Python 3000.The main objection is that Python 2.x already has a function named “input”,and, even though it is not going to be included in Python 3000,having a built-in function with the same name but different semantics mayconfuse programmers migrating from 2.x to 3000. Certainly, this is no problemfor beginners, and the scope of the problem is unclear for more experiencedprogrammers, since raw_input(), while popular with many, is not inuniversal use. In this instance, the good it does for beginners could beseen to outweigh the harm it does to experienced programmers -although it could cause confusion for people reading older books or tutorials.
The rationale for accepting the renaming can be found here[4].
This document has been placed in the public domain.
Source:https://github.com/python/peps/blob/main/peps/pep-3111.rst
Last modified:2025-02-01 08:59:27 GMT