#!/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 locale import sys text = u'pi: π' # Configure locale from the user's environment settings. locale.setlocale(locale.LC_ALL, '') # Wrap stdout with an encoding-aware writer. lang, encoding = locale.getdefaultlocale() print 'Locale encoding :', encoding sys.stdout = codecs.getwriter(encoding)(sys.stdout) print 'With wrapped stdout:', text