diff options
| author | Steven D'Aprano <steve@pearwood.info> | 2016-08-24 02:40:31 +1000 |
|---|---|---|
| committer | Steven D'Aprano <steve@pearwood.info> | 2016-08-24 02:40:31 +1000 |
| commit | 9ff4fb36199f94818d97be56d0b3ab1c9e989209 (patch) | |
| tree | a4ee9040e52bfe8f73278c90f543ef64cd55b766 /Lib/code.py | |
| parent | f06c7b6f377692b82f2da449cb7e9460f474f434 (diff) | |
| parent | 0a21c729ebaca9e2e929a1e04c7404c5349aa1f4 (diff) | |
| download | cpython-git-9ff4fb36199f94818d97be56d0b3ab1c9e989209.tar.gz | |
Automated merge with ssh://hg.python.org/cpython
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 c8b72042e0..23295f4cf5 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__": |
