Open
Description
i found the file i/o section to be refreshing and enlightening, but it works only on files we open, which unfortunately doesn't work with stdin/stdout and friends.
there are various idioms out there to fix this. here i have seen:
input_stream = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8')
and here i have seen:
sys.stdout = codecs.getwriter('utf8')(sys.stdout)
both seem pretty ugly to me - is there a better way to do this in both py2 and py3 that we should document here?
my favorite right now is PYTHONIOENCODING=utf-8
but then that can't be done from within the program itself.