]> granicus.if.org Git - python/commitdiff
SF Patch #103227 by mwh: make code.py appreciate softspace
authorGuido van Rossum <guido@python.org>
Sat, 13 Jan 2001 22:10:41 +0000 (22:10 +0000)
committerGuido van Rossum <guido@python.org>
Sat, 13 Jan 2001 22:10:41 +0000 (22:10 +0000)
Lib/code.py

index 9ef632273136779c74711847cef552082910d08f..b308a5807c6084659f091c121101686608ab14bb 100644 (file)
@@ -10,6 +10,17 @@ import string
 import traceback
 from codeop import compile_command
 
+def softspace(file, newvalue):
+    oldvalue = 0
+    try:
+        oldvalue = file.softspace
+    except AttributeError:
+        pass
+    try:
+        file.softspace = newvalue
+    except TypeError: # "attribute-less object" or "read-only attributes"
+        pass
+    return oldvalue
 
 class InteractiveInterpreter:
     """Base class for InteractiveConsole.
@@ -90,6 +101,9 @@ class InteractiveInterpreter:
             raise
         except:
             self.showtraceback()
+        else:
+            if softspace(sys.stdout, 0):
+                print
 
     def showsyntaxerror(self, filename=None):
         """Display the syntax error that just occurred.