【发布时间】:2010-10-29 21:03:31
【问题描述】:
我有这个代码:
def getch(self):
if os.name == 'posix':
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(fd)
ch = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
elif os.name == 'nt':
ch = msvcrt.getch()
return ch
这在 python 2.6 和 2.7 上运行得很好,但是每当我尝试在 python 3.0 上测试它时,stdin.read 调用就会打印出一个新行,我认为这可能是因为 python 3 更改为 sys.标准输入、标准输出和标准错误,但我不知道如何修复它
编辑:在 OS X 10.6.4 python 3.1 和 Ubuntu 9.04 python 2.6 上运行这发生在我身上。
【问题讨论】:
标签: python terminal python-3.x