How does Python implement single-character input from a string instead of reading the entire string, as does input() and, accordingly, printing one character at the end of the current line? those. analogues of getchar() and putchar() in putchar()
|
sys.stdout.write('x')- andy.37char = sys.stdin.read(1)- andy.37getchar()andputchar()work with bytes, not characters. 2- you probably want an analogue ofgetch()(read the input from the console / terminal without waiting for the Enter), notgetchar(). 3- It’s easy toprint/sys.stdout.write, justsys.stdout.flush()afterprint/sys.stdout.writeto free up the buffer. - jfs