I want to read char one by one and show to astrix *
.
Characters can be showed as *
, but I cannot exit by pushing Enter.
This is my code:
import sys, tty, termios
def getch():
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())
ch = sys.stdin.read(1)
sys.stdout.write('*')
except:
print "ex"
finally:
termios.tcsetattr(fd, termios.TCSADRAIN,old_settings)
return ch
If I input Enter where ch = sys.stdin.read(1)
, what is the return value?