Python, Press Any Key To Exit

后端 未结 9 1168
渐次进展
渐次进展 2020-12-31 06:16

So, as the title says, I want a proper code to close my python script. So far, I\'ve used input(\'Press Any Key To Exit\'), but what that does, is generate a er

相关标签:
9条回答
  • 2020-12-31 07:09
    a = input('Press a key to exit')
    if a:
        exit(0)
    
    0 讨论(0)
  • 2020-12-31 07:11

    Ok I am on Linux Mint 17.1 "Rebecca" and I seem to have figured it out, As you may know Linux Mint comes with Python installed, you cannot update it nor can you install another version on top of it. I've found out that the python that comes preinstalled in Linux Mint is version 2.7.6, so the following will for sure work on version 2.7.6. If you add raw_input('Press any key to exit') it will not display any error codes but it will tell you that the program exited with code 0. For example this is my first program. MyFirstProgram. Keep in mind it is my first program and I know that it sucks but it is a good example of how to use "Press any key to Exit" BTW This is also my first post on this website so sorry if I formatted it wrong.

    0 讨论(0)
  • 2020-12-31 07:14

    If you are on windows then the cmd pause command should work, although it reads 'press any key to continue'

    import os
    os.system('pause')
    

    The linux alternative is read, a good description can be found here

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