How to stop Python closing immediately when executed in Microsoft Windows

后端 未结 15 2210
北荒
北荒 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条回答
  • 2020-12-02 23:26

    Just add an line of code in idle "input()"

    0 讨论(0)
  • 2020-12-02 23:29

    Depending on what I'm using it for, or if I'm doing something that others will use, I typically just input("Do eighteen backflips to continue") if it's just for me, if others will be using I just create a batch file and pause it after

    cd '/file/path/here'
    python yourfile.py
    pause 
    

    I use the above if there is going to be files renamed, moved, copied, etc. and my cmd needs to be in the particular folder for things to fall where I want them, otherwise - just

    python '/path/to/file/yourfile.py'
    pause
    
    0 讨论(0)
  • 2020-12-02 23:32

    In Python 3, add the following to the end of your code:

    input('Press ENTER to exit')
    

    This will cause the program to wait for user input, with pressing ENTER causing the program to finish.

    You can double click on your script.py file in Windows conveniently this way.

    0 讨论(0)
提交回复
热议问题