Skip to content

Instantly share code, notes, and snippets.

@zhester
Created March 10, 2015 14:05
Show Gist options
  • Save zhester/2d9f5699bd87466d7496 to your computer and use it in GitHub Desktop.
Save zhester/2d9f5699bd87466d7496 to your computer and use it in GitHub Desktop.
Python boilerplate to encode strings sent to stdout as UTF-8
# write UTF-8 to stdout
if sys.stdout.encoding != 'UTF-8':
import codecs
writer = codecs.getwriter( 'UTF-8' )
sys.stdout = writer( sys.stdout )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment