Python: 从命令行清除控制台输入字符队列 clear console input / keypress queuePython: 从命令行清除控制台输入字符队列 clear console input / keypress queuePython: 从命令行清除控制台输入字符队列 clear console input / keypress queuePython: 从命令行清除控制台输入字符队列 clear console input / keypress queue
  • 首页
  • 博客
  • 书签
  • 文件
  • 分析
  • 登录

Python: 从命令行清除控制台输入字符队列 clear console input / keypress queue

发表 admin at 2022年6月8日
类别
  • Python
标签
清除Windows和UNIX上的输入缓冲区:

def flush_input():
    try:
        import msvcrt
        while msvcrt.kbhit():
            msvcrt.getch()
    except ImportError:
        import sys, termios    #for linux/unix
        termios.tcflush(sys.stdin, termios.TCIOFLUSH)

如果仅需要Windows支持,可使用以下方法:

def flush_input():
    while msvcrt.kbhit():
        msvcrt.getch()

发表回复 取消回复

您的电子邮箱地址不会被公开。 必填项已用*标注

类别

  • Cat
  • Python
  • MySQL
  • Django
  • Html/CSS
  • JavaScript
  • Vue
  • RegExp
  • php
  • Practice
  • Virtualization
  • Linux
  • Windows
  • Android
  • NAS
  • Software
  • Hardware
  • Network
  • Router
  • Office
  • WordPress
  • SEO
  • English
  • Games
  • Recipes
  • living
  • Memorandum
  • Essays
  • 未分类

归档

©2015-2023 艾丽卡 Blog support@alaica.com
      ajax-loader