c = codecs.getwriter('UTF-8') sys.stdout = c(sys.stdout, 'replace')