# -*- coding: utf-8 -*-
import sys, locale, os

# LC_ALL=C python3 encoding.py
# UnicodeEncodeError

print(sys.stdout.encoding)
print(sys.stdout.isatty())
print(locale.getpreferredencoding())
print(sys.getfilesystemencoding())
print(os.environ.get("PYTHONIOENCODING"))
encoding = sys.stdout.encoding
if not 'PYTHONIOENCODING' in os.environ and (not encoding or encoding != 'UTF-8'):
  import six
  if six.PY3:
    sys.stdout = open(sys.stdout.fileno(), mode='w', encoding='utf8', buffering=1)
  else:
    import codecs
    sys.stdout = codecs.getwriter('utf8')(sys.stdout)

print(u'☺ ☻')

