Skip to content

should document how to deal with stdin/stdout and unicode #241

@anarcat

Description

@anarcat

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions