How to keep a Python script output window open?

前端 未结 23 2596
挽巷
挽巷 2020-11-22 10:54

I have just started with Python. When I execute a python script file on Windows, the output window appears but instantaneously goes away. I need it to stay there so I can an

23条回答
  •  难免孤独
    2020-11-22 10:55

    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.

    This would just show a cursor with no text:

    raw_input() 
    

    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') 
    raw_input()
    

    Note!
    (1) In python 3, there is no raw_input(), just input().
    (2) Use single quotes to indicate a string; otherwise if you type doubles around anything, such as "raw_input()", it will think it is a function, variable, etc, and not text.

    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")
    input()
    

    Hopefully this helps others who might be starting out and still haven't figured out how the computer thinks yet. It can take a while. :o)

提交回复
热议问题