Skip to content

Instantly share code, notes, and snippets.

@methane
Created August 7, 2012 00:46
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 methane/3280063 to your computer and use it in GitHub Desktop.
Save methane/3280063 to your computer and use it in GitHub Desktop.
def reopen_stdio_with_encoding(encoding='utf-8'):
import io
import sys
def reopen(file):
file.__init__(file.detach(),
line_buffering=file.line_buffering,
encoding=encoding)
reopen(sys.stdout)
reopen(sys.stderr)
reopen(sys.stdin)
reopen_stdio_with_encoding()
print("ほげほげ")
@methane
Copy link
Author

methane commented Aug 7, 2012

re-init rather than opening other TextIOWrapper.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment