python - Python:在输入之前清除键盘模块按下的键
问题描述
我有一堂课,就像这样:
import keyboard
import numpy as np
class Something():
def __init__(self, modulo):
self.modulo = modulo
def pick_number(self):
print ("In this case it seems simple to avoid, but I really need you press q")
while True:
keyboard.wait("q")
n=np.random.randint(0,1000)
print(n)
while n%self.modulo!=0:
n=np.random.randint(0,1000)
print(n)
self.number=n
break
def add_number(self):
try:
n=int(input("Type a number..."))
self.number+=n
return self.number
except:
print("Please put a correct number...")
然后,我执行 Something() 的新实例:
instance = Something(11)
instance.pick_number()
instance.add_number()
当调用 add_number() 时,我在输入提示中已经有了一个“q”......如果我想使用 ENTER 而不是 q,那会非常令人不安......有没有办法清除那个“内存”,有一个空的输入字段?
解决方案
推荐阅读
- c# - 如何在 Xamarin.ios 中实现日历日期选择器而不是默认日期选择器
- google-apps-script - 如果我部署谷歌应用脚本,是否有机会在谷歌搜索中被搜索到?
- c# - 正则表达式提取 2 个正斜杠之后的字符,但如果两个正斜杠(和后面的文本)都在双引号之间,则忽略
- c++ - C++ 非阻塞发送/接收仅在一侧工作(客户端或服务器)
- reactjs - 如何在amcharts4中设置每列的轴引导范围
- javascript - 如何在 vite2 中内联 css
- c++ - 向量初始化中使用的make_pair是错误的吗?
- lit - 为什么有一个“。” 在点亮样本的选项中?
- kdb - kdb: longList@dictionary behavior
- bash - 这个命令在 VSCode 的 CLI 启动脚本中做了什么?