【发布时间】:2012-04-11 19:26:21
【问题描述】:
在 Windows 中,当 Python 脚本退出时,命令提示符窗口会关闭。如果它从错误中退出,它会在您阅读任何内容之前关闭。即使出现错误,我也一直在使用它来保持窗口打开:
if __name__ == '__main__':
try:
main()
except BaseException as e:
print('Error:')
print(e)
raise
finally:
raw_input('(Press <Enter> to close)')
如果main() 调用sys.exit(),它会起作用,但对于语法错误等情况不起作用。有没有更好的办法?
【问题讨论】:
标签: python windows command-prompt