당신이 출력에 UTF-8 문자를 원하는 경우, 당신은 또한 확실히 파이썬
$ export PYTHONIOENCODING=ascii
$ python
Python 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24)
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.stdout.encoding
'ascii'
>>> for i, j in enumerate(u'Сон'): print '%d: %s' % (i+1, j)
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character u'\u0421' in position 3: ordinal not in range(128)
$ export PYTHONIOENCODING=utf-8
$ python
Python 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24)
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.stdout.encoding
'utf-8'
>>> for i, j in enumerate(u'Сон'): print '%d: %s' % (i+1, j)
...
1: С
2: о
3: н
>>>
가 귀하의 질문에 대답에이 링크를합니까 사용할 인코딩을 알고 확인해야합니다 - http://stackoverflow.com/questions/8873517/printing-utf-8-encoded-byte-string – Gangadhar
또는 변수가 리터럴이 아닌 경우 'utf8_string.decode ('utf-8 ')'. – agf