Issue 1600157: [PATCH] Quitting The Interpreter (original) (raw)

When i type 'quit' in the interpreter, i get a nice little class and method yelling at me, instead of just quitting.

PATCH:

def setquit():

    class Quitter(object):
        def __init__(self, name):
            self.name = name
        def __repr__(self):
            quit()
        def __call__(self, code=None):
            # Shells like IDLE catch the SystemExit, but listen when their
            # stdin wrapper is closed.
            try:
                sys.stdin.close()
            except:
                pass
            raise SystemExit(code)
    __builtin__.quit = Quitter('quit')
    __builtin__.exit = Quitter('exit')