CreateMutex
까보면 다나와~
2017/03 (1)

Python 2.7 Unicode 관련

>>> import sys


#터미널 인코딩 확인

>>> sys.stdin.encoding

'utf-8'


>>> han = '한글'

>>> uhan = u'한글'


>>> type(han)

<type 'str'>

>>> type(uhan)

<type 'unicode'>


#utf-8 일때, cp949는 다른 결과값이 나옴

>>> han

'\xed\x95\x9c\xea\xb8\x80'

>>> uhan

u'\ud55c\uae00'


#터미널이 'cp949'인 경우 han.decode('utf-8')시 에러

#터미널이 'utf-8'인 경우 han.decode('cp949')시 에러

>>> han.decode('utf-8')

u'\ud55c\uae00'

>>> uhan.encode('utf-8')

'\xed\x95\x9c\xea\xb8\x80'



  Comments,     Trackbacks