Skip to content

Instantly share code, notes, and snippets.

@mitsuhiko
Created April 27, 2014 12:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mitsuhiko/11344857 to your computer and use it in GitHub Desktop.
Save mitsuhiko/11344857 to your computer and use it in GitHub Desktop.
>>> import io
>>> sys.stdin.encoding
'ANSI_X3.4-1968'
>>> stdin = sys.stdin
>>> correct_stdin = io.TextIOWrapper(stdin.buffer, 'utf-8')
>>> correct_stdin.readline()
foobar
'foobar\n'
>>> del correct_stdin
>>> stdin.readline()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: I/O operation on closed file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment