I am wondering how to read a single (possibly multibyte) character from a file (for example sys.stdin), without having to wait for any further caracters, end of the line or end of the file. The primary use is to be able to read from standard input as soon as a character is available.
I am primarily using python 3.
The following code illustrates a way to do this in C, where the read character is simply printed to standard out again immediately:
#include <stdio.h>
#include <wchar.h>
#include <locale.h>
int main(void)
{
setlocale(LC_CTYPE, "");
wint_t wc;
while ((wc = fgetwc(stdin)) != WEOF)
{
fputwc(wc, stdout);
}
}