也许我在一个问题标题中写了一个奇怪的问题,我试着解释一下。
我正在尝试在基于Linux的系统中执行密码输入(键入时不显示符号)。
我发现了一个功能。为什么使用打印功能的结束参数改变输出时间?
def getchar():
import tty, termios, sys
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())
ch = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return ch
pwd = ''
print('Type password:', end=' ') # HERE IS THE PROBLEM
while True:
ch = getchar()
if ch == '\r':
break
pwd += ch
print(pwd)
线 '类型的密码:' 会出现while
循环结束后。 这是为什么?我该怎么办?
'sys.stdout.flush()' – zondo