执行以下代码后,当我按 control+C 时,执行结束,没有任何东西打印到控制台
import time
x = 1
try:
while True:
print x
time.sleep(.3)
x += 1
except KeyboardInterrupt:
print "Bye"
finally:
print "this one"
代码中存在缩进问题。如果更改为:
import time
x = 1
try:
while True:
print x
time.sleep(.3)
x += 1
except KeyboardInterrupt:
print "Bye"
finally:
print "this one"
输出为:
1
2
3
4
5
6
Bye
this one
当我以精美的文本执行代码时出现问题,从终端运行时工作正常