开发者

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

This question already has answers here: How to keep a Python script output window open? (26 answers) Closed 8 years ago.

I'm new to programming, especially Python. I'm trying to make an application that converts Fahr开发者_运维百科enheit to Celsius, but I don't know how to make the program stay open. Whenever it reaches the end of the code, it automatically closes before the user can see his or her results. I'm using Python 2.6.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜