In Python 3, it is possible to open a file object using an \"integer file descriptor\" with the format:
stdout = open(1, \"w\")
stdout.write(\"Hello World\")
>
syntax is handled by the shell before python is invoked. It connects stdout
to the given file, as 2>
does for stderr
and <
does for stdin
.
All that said, 0
, 1
, and 2
are file descriptors reserved for stdin
, stdout
, and stderr
respectively (which is why 2>
is the syntax to redirect stderr
).
So 0
is a valid file descriptor, but one that is your stdin
, which you're opening again for writing. This ends up writing to the terminal it seems, since that's where stdin
was going to write.