If you need a pure-Python solution, you will have to wrap your script with a try / except clause:
import traceback try: ... your script ... except: traceback.print_exc() raw_input("Press Enter to close")
Thus, the window will remain open, even if your code throws an exception. It will still be closed when Python cannot parse the script, that is, when you have a syntax error. If you want to fix this, I would suggest a good IDE that will allow you to develop in a more pleasant way ( PyCharm and PyDev come to mind).
source share