如何让我的 python 脚本等待用户按下任意键?
In Python 3, use input()
:
input("Press Enter to continue...")
In Python 2, use raw_input()
:
raw_input("Press Enter to continue...")
但这只会等待用户按 Enter 键。
在 Windows/DOS 上,人们可能想使用msvcrt
. The msvcrt
模块使您可以访问 Microsoft Visual C/C++ 运行时库 (MSVCRT) 中的许多函数:
import msvcrt as m
def wait():
m.getch()
这应该等待按键。
Notes:
在Python 3中,raw_input()
不存在。
在Python 2中,input(prompt)
相当于eval(raw_input(prompt))
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)