diff options
Diffstat (limited to 'Lib/code.py')
-rw-r--r-- | Lib/code.py | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/Lib/code.py b/Lib/code.py index c8b7204..23295f4 100644 --- a/Lib/code.py +++ b/Lib/code.py @@ -186,7 +186,7 @@ class InteractiveConsole(InteractiveInterpreter): """Reset the input buffer.""" self.buffer = [] - def interact(self, banner=None): + def interact(self, banner=None, exitmsg=None): """Closely emulate the interactive Python console. The optional banner argument specifies the banner to print @@ -196,6 +196,11 @@ class InteractiveConsole(InteractiveInterpreter): to confuse this with the real interpreter -- since it's so close!). + The optional exitmsg argument specifies the exit message + printed when exiting. Pass the empty string to suppress + printing an exit message. If exitmsg is not given or None, + a default message is printed. + """ try: sys.ps1 @@ -230,7 +235,10 @@ class InteractiveConsole(InteractiveInterpreter): self.write("\nKeyboardInterrupt\n") self.resetbuffer() more = 0 - self.write('now exiting %s...\n' % self.__class__.__name__) + if exitmsg is None: + self.write('now exiting %s...\n' % self.__class__.__name__) + elif exitmsg != '': + self.write('%s\n' % exitmsg) def push(self, line): """Push a line to the interpreter. @@ -268,7 +276,7 @@ class InteractiveConsole(InteractiveInterpreter): -def interact(banner=None, readfunc=None, local=None): +def interact(banner=None, readfunc=None, local=None, exitmsg=None): """Closely emulate the interactive Python interpreter. This is a backwards compatible interface to the InteractiveConsole @@ -280,6 +288,7 @@ def interact(banner=None, readfunc=None, local=None): banner -- passed to InteractiveConsole.interact() readfunc -- if not None, replaces InteractiveConsole.raw_input() local -- passed to InteractiveInterpreter.__init__() + exitmsg -- passed to InteractiveConsole.interact() """ console = InteractiveConsole(local) @@ -290,7 +299,7 @@ def interact(banner=None, readfunc=None, local=None): import readline except ImportError: pass - console.interact(banner) + console.interact(banner, exitmsg) if __name__ == "__main__": |