Python, Press Any Key To Exit

后端 未结 9 1291
渐次进展
渐次进展 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:04

    I would discourage platform specific functions in python if you can avoid them, but you could use the built-in msvcrt module.

    from msvcrt import getch
    
    junk = getch() # Assign to a variable just to suppress output. Blocks until key press.
    

提交回复
热议问题