@@ -186,7 +186,7 @@ def resetbuffer(self):
186186 """Reset the input buffer."""
187187 self .buffer = []
188188
189- def interact (self , banner = None ):
189+ def interact (self , banner = None , exitmsg = None ):
190190 """Closely emulate the interactive Python console.
191191
192192 The optional banner argument specifies the banner to print
@@ -196,6 +196,11 @@ def interact(self, banner=None):
196196 to confuse this with the real interpreter -- since it's so
197197 close!).
198198
199+ The optional exitmsg argument specifies the exit message
200+ printed when exiting. Pass the empty string to suppress
201+ printing an exit message. If exitmsg is not given or None,
202+ a default message is printed.
203+
199204 """
200205 try :
201206 sys .ps1
@@ -230,7 +235,10 @@ def interact(self, banner=None):
230235 self .write ("\n KeyboardInterrupt\n " )
231236 self .resetbuffer ()
232237 more = 0
233- self .write ('now exiting %s...\n ' % self .__class__ .__name__ )
238+ if exitmsg is None :
239+ self .write ('now exiting %s...\n ' % self .__class__ .__name__ )
240+ elif exitmsg != '' :
241+ self .write ('%s\n ' % exitmsg )
234242
235243 def push (self , line ):
236244 """Push a line to the interpreter.
@@ -268,7 +276,7 @@ def raw_input(self, prompt=""):
268276
269277
270278
271- def interact (banner = None , readfunc = None , local = None ):
279+ def interact (banner = None , readfunc = None , local = None , exitmsg = None ):
272280 """Closely emulate the interactive Python interpreter.
273281
274282 This is a backwards compatible interface to the InteractiveConsole
@@ -280,6 +288,7 @@ def interact(banner=None, readfunc=None, local=None):
280288 banner -- passed to InteractiveConsole.interact()
281289 readfunc -- if not None, replaces InteractiveConsole.raw_input()
282290 local -- passed to InteractiveInterpreter.__init__()
291+ exitmsg -- passed to InteractiveConsole.interact()
283292
284293 """
285294 console = InteractiveConsole (local )
@@ -290,7 +299,7 @@ def interact(banner=None, readfunc=None, local=None):
290299 import readline
291300 except ImportError :
292301 pass
293- console .interact (banner )
302+ console .interact (banner , exitmsg )
294303
295304
296305if __name__ == "__main__" :
0 commit comments