栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Python中的主要侦听器?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Python中的主要侦听器?

不幸的是,做到这一点并不容易。如果您要制作某种文本用户界面,则可能需要研究

curses
。如果您想要像通常在终端中那样显示内容,但又想要这样的输入,那么您将不得不使用
termios
,不幸的是,在Python中,该文档似乎文献很少。不幸的是,这些选项都不是那么简单。此外,它们在Windows下不起作用。如果您需要它们在Windows下运行,则必须使用PDCurses代替
curses
或pywin32而不是
termios


我能够做到这一点。它打印出您键入的键的十六进制表示形式。正如我在对您的问题的评论中所说的那样,箭是很棘手的。我想你会同意的。

#!/usr/bin/env pythonimport sysimport termiosimport contextlib@contextlib.contextmanagerdef raw_mode(file):    old_attrs = termios.tcgetattr(file.fileno())    new_attrs = old_attrs[:]    new_attrs[3] = new_attrs[3] & ~(termios.ECHO | termios.ICANON)    try:        termios.tcsetattr(file.fileno(), termios.TCSADRAIN, new_attrs)        yield    finally:        termios.tcsetattr(file.fileno(), termios.TCSADRAIN, old_attrs)def main():    print 'exit with ^C or ^D'    with raw_mode(sys.stdin):        try: while True:     ch = sys.stdin.read(1)     if not ch or ch == chr(4):         break     print '%02x' % ord(ch),        except (KeyboardInterrupt, EOFError): passif __name__ == '__main__':    main()


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/659932.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号