-
-
Save 43trh/366df5c312f537e891800df53c8150fa to your computer and use it in GitHub Desktop.
Standard Python header
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# Python *sucks* at UTF-8 (don't tell me "It's fixed in Python 3"; I don't care, plus no one uses Python 3) | |
# If you put this at the top of every Python script, however, it get rids of most of the headaches dealing with STDIN | |
# and STDOUT (basically, akin to "perl -C31"). I don't know if it's all necessary; I just know that if I put it at | |
# the top of my scripts, most of the problems go away, and I can stop thinking about it. | |
import sys | |
import codecs | |
reload(sys) | |
sys.setdefaultencoding('utf-8') | |
sys.stdin = codecs.getreader('utf-8')(sys.stdin) | |
sys.stdout = codecs.getwriter('utf-8')(sys.stdout) | |
sys.stdout.encoding = 'utf-8' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment