He is surprised because he assumed that the input() function would use stdin as well to get the input. Which seems is not the case (for him at least) for some reason.
Couldn't really replicate that behavior on Linux. Maybe it works different on Windows?
Edit: Yeah just installed python3.9 on Windows and it behaves different than the Linux version.
On Windows input() doesn't error out. On Linux input() uses stdin and throws an Exception.
Well, let's see. I redeclared stdin to another file handler. Then, I created anew handler to the same file. Then, other the other handler, I wrote to the file. When I called input(), it flushed those contents onto the screen. How do you exaplin that?
input() seems to return the content of the sys.stdin pseudo-file. sys.stdin is part of the standard file object interface(if I am not mistaken). And changing sys.stdin seems to directly affect what input() returns.
6
u/RapidCatLauncher Jul 26 '21
This can be used in a much more useful manner:
13
u/[deleted] Jul 25 '21
How though