[Python-checkins] peps: Updated discussion, including two open issues. I've also changed the

georg.brandl python-checkins at python.org
Wed Mar 23 21:25:02 CET 2011


http://hg.python.org/peps/rev/a92de4b1c4b9
changeset:   103:a92de4b1c4b9
user:        Barry Warsaw <barry at python.org>
date:        Tue Aug 15 22:45:06 2000 +0000
summary:
  Updated discussion, including two open issues.  I've also changed the
Python-Version to 2.1 since this probably needs more discussion,
unless the BDFL pronounces favorably on it.

files:
  pep-0214.txt |  59 +++++++++++++++++++++++++--------------
  1 files changed, 37 insertions(+), 22 deletions(-)


diff --git a/pep-0214.txt b/pep-0214.txt
--- a/pep-0214.txt
+++ b/pep-0214.txt
@@ -1,12 +1,13 @@
 PEP: 214
 Title: Extended Print Statement
 Version: $Revision$
-Owner: bwarsaw at beopen.com (Barry A. Warsaw)
-Python-Version: 2.0
+Author: bwarsaw at beopen.com (Barry A. Warsaw)
+Python-Version: 2.1
 Status: Draft
+Created: 24-Jul-2000
+Post-History:
 
 
-
 Introduction
 
     This PEP describes a syntax to extend the standard `print'
@@ -20,7 +21,6 @@
     record.
 
 
-
 Justification
 
     `print' is a Python keyword and introduces the print statement as
@@ -52,8 +52,10 @@
     if we added a call to a function that actually did want to print
     to stdout, this output too would get redirected to the logfile.
 
+    This approach is also very inconvenient for interleaving prints to
+    various output streams.
 
-
+
 Proposal
 
     This proposal introduces a syntax change to the print statement,
@@ -74,28 +76,42 @@
         print >> sys.stdout, 'hello world'
 
 
-
+Open Issues
+
+    What should the following do?
+
+        print >> file
+        print >> file,
+
+    In the current implementation (see below), the first is a
+    SyntaxError and the second prints nothing to file.  This is likely
+    counterintuitive; the first should print just a newline, making
+    these equivalent:
+
+        print >> sys.stdout
+        print
+
+    The second should print just a space and no newline to file.  It
+    doesn't have a non-extended print equivalent, since this is
+    illegal:
+
+        print ,
+
+    The closes equivalent is:
+
+        print '',
+    
+
 Reference Implementation
 
     A reference implementation, in the form of a patch against the
     Python 2.0 source tree, is available on SourceForge's patch
-    manager[2].  The approach this patch takes is to introduce two new
-    opcodes, one which temporarily rebinds sys.stdout to the specified
-    file object, performs the print as normal, and then bind
-    sys.stdout back to sys.__stdout__ (which is the real physical
-    standard out and should not be changed).  In some ways this is
-    equivalent to the try/finally idiom above, except that the
-    rebinding of sys.stdout is in effect only for the duration of the
-    print statement itself.
+    manager[2].  This approach adds two new opcodes, PRINT_ITEM_TO and
+    PRINT_NEWLINE_TO, which simply pop the file like object off the
+    top of the stack and use it instead of sys.stdout as the output
+    stream.
 
-    An alternative approach is possible, where only one new opcode is
-    added.  This opcode would be exactly like the existing PRINT_ITEM
-    opcode except that it would find the target file object at the top
-    of the stack, and use this file instead of digging it out of
-    sys.stdout.
 
-
-
 Alternative Approaches
 
     An alternative to this syntax change has been proposed (originally
@@ -139,7 +155,6 @@
     in between each item.
 
 
-
 References
 
     [1] http://www.python.org/doc/current/ref/print.html

-- 
Repository URL: http://hg.python.org/peps


More information about the Python-checkins mailing list