How to stop Python closing immediately when executed in Microsoft Windows

后端 未结 15 2225
北荒
北荒 2020-12-02 22:43

I have just started college and we are going to be using python. We really have done nothing so I have downloaded the program and done some print commands, and that\'s it.

15条回答
  •  旧时难觅i
    2020-12-02 23:10

    I think I am too late to answer this question but anyways here goes nothing.

    I have run in to the same problem before and I think there are two alternative solutions you can choose from.

    1. using sleep(_sometime)

    from time import * sleep(10)

    1. using a prompt message (note that I am using python 2.7)

    exit_now = raw_input("Do you like to exit now (Y)es (N)o ? ")'

    if exit_now.lower() = 'n'

    //more processing here

    Alternatively you can use a hybrid of those two methods as well where you can prompt for a message and use sleep(sometime) to delay the window closing as well. choice is yours.

    please note the above are just ideas and if you want to use any of those in practice you might have to think about your application logic a bit.

提交回复
热议问题