How do I prevent my Python application from automatically closing once reaching the end of code? [duplicate]

旧时模样 提交于 2019-12-01 21:16:05

Well, I guess you mean the terminal that Windows opens for you when you run a python file is closed too fast. You can add raw_input('Press Enter to exit') right before your program would exit. It tells Python to wait for input before exiting.

As the other people say, just ask for input to get it to hold. However, I would recommend running your Python scripts in a different manner in Windows. Using the IDLE IDE (should have come with your distribution), just open the script you want to run and press F5. Then, not only can you see the output for as long as you like, but you can also examine any variables that were assigned interactively. This is very handy especially when you are just starting to program in Python.

You can also run scripts from the command line, but I would recommend use IDLE if you're just starting out.

Matt Joiner

Take a look at this question, which addresses this problem on Windows, which I'm guessing is your platform.

ask user to enter one more variable and print "Press enter to exit..."

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!