37,719
社区成员
发帖
与我相关
我的任务
分享
tim@tim-eee:~$ python
Python 2.7.3 (default, Apr 20 2012, 22:39:59)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> def mainloop():
... try:
... while True:
... pass
... except KeyboardInterrupt, e:
... print "break out"
... return
...
>>> mainloop()
^Cbreak out
>>>
#!/usr/bin/env python
try:
i = 0;
while 1:
i += 1
print "%d loop" % i
except KeyboardInterrupt, e:
print "\ntest end"