关闭python解释器的方式_Python CTRL + C退出解释器?

Python 2.73

Why is it on my laptop when I hit CTRL+C, I can exit the interpreter and on my desktop hitting CTRL+C will make the interpreter shoot back at me a KeyboardInterrupt message. How can I get rid of this KeyboardInterrupt and go back to exiting with CTRL+C!

On my desktop it's required to input CTRL+Z and hitting enter to exit.

I am using PowerShell on both computer. Same 64bit, one is Win7 one is Win8

解决方案

You could change the signal handler for CTRL-C to something that exits the interpreter:

import signal

import sys

signal.signal(signal.SIGINT, lambda number, frame: sys.exit())

You could probably put that code in a file to be run automatically when an interactive session starts, then set the environment variable PYTHONSTARTUP to the name of that file:

你可能感兴趣的:(关闭python解释器的方式)