代码如下:
#encoding=utf-8
print '中国'
#跨平台读取无缓存字符
try: #windows
import msvcrt
except ImportError: #unix
def getch():
import sys,tty,termios
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)
return ch
print 'Enter somthing'
c = msvcrt.getch()
print c
打印结果如下:后面为控制台打印
中国
Enter somthing
>>> c = msvcrt.getch()
>>>
>>> print c
o
>>>