Python - Handle CTRL+D with 'import signal'
问题 I can currently handle CTRL + C via: def hand_inter(signum, frame): print 'hey, nice job.' signal.signal(signal.SIGINT, hand_inter) However I am required to also handle CTRL + D yet cannot find the appropriate "signal.CTRL+D" call for signum. 回答1: Ctrl + D is not a signal, it's end of file. If you have an interactive program, you will be most probably reading STDIN and Ctrl + D is way how user says that the input is over. Outside this context it does not have any special meaning. The code