#!/usr/bin/env python # encoding: utf-8 # # Copyright (c) 2010 Doug Hellmann. All rights reserved. # """Printing unicode text to sys.stdout. """ #end_pymotw_header import codecs import sys text = u'pi: π' # Wrap sys.stdout with a writer that knows how to handle encoding # Unicode data. wrapped_stdout = codecs.getwriter('UTF-8')(sys.stdout) wrapped_stdout.write(u'Via write: ' + text + '\n') # Replace sys.stdout with a writer sys.stdout = wrapped_stdout print u'Via print:', text