In this next example, I use double quotes and it won't work because it thinks there is a break in the quotes between "the" and "function" even though when you read it, your own mind can make perfect sense of it: print("You have reached the end and the "input()" function is keeping the window open") "raw_input()", it will think it is a function, variable, etc, and not text. (2) Use single quotes to indicate a string otherwise if you type doubles around anything, such as (1) In python 3, there is no raw_input(), just This next example would give you a clear message that the program is done and not waiting on another input prompt within the program: print('You have reached the end and the "raw_input()" function is keeping the window open') This would just show a cursor with no text: raw_input() To just keep the window open I agree with Anurag and this is what I did to keep my windows open for short little calculation type programs. To keep the window open in any case: if _name_ = '_main_':įor Python3 you'll have to use input() in place of raw_input(), and of course adapt the print statements. To keep your window open in case of exception (yet, while printing the exception) Python 2 if _name_ = '_main_': That drops you to a python shell after the end of the program, with the program environment loaded, so you may further play with the variables and call functions and methods. I find it particularly useful to configure it as " python -i myscript.py" when running. Other editors allow you to configure the command line it uses to run your program. Some editors prepared for python will automatically pause for you after execution. Specially annoying when testing other people's scripts. That method is annoying because you have to modify the script, and have to remember removing it when you're done. at the end of the script makes it wait for the Enter key. When the program ends, it'll drop you back to the cmd prompt instead of closing the window.Īdd code to wait at the end of your script. Just check on how to edit environment variables on Windows, and add C:\PYTHON26 (or whatever directory you installed python to). Open a command prompt and type: python myscript.pyįor that to work you need the python executable in your path. Run the program from an already-open terminal.
0 Comments
Leave a Reply. |