In [19]: s='\xebmail'

 

In [20]: s

Out[20]: 'ëmail'

 

In [28]: file=open('unicode.txt','w',encoding='utf-8')

 

In [29]: file.write(s)

Out[29]: 5

 

In [30]: file.close()

 

In [31]: file=open('unicode16.txt','w',encoding='utf-16')

 

In [32]: file.write(s)

Out[32]: 5

 

In [33]: file.close()

 

In [34]: raw=open('unicode.txt','rb').read()

 

In [35]: raw

Out[35]: b'\xc3\xabmail'

 

In [36]: len(raw)

Out[36]: 6

 

In [37]: raw2=open('unicode16.txt','rb').read()

 

In [38]: raw2

Out[38]: b'\xff\xfe\xeb\x00m\x00a\x00i\x00l\x00'

 

In [39]: len(raw2)

Out[39]: 12

 

In [40]: raw.decode('utf-8')

Out[40]: 'ëmail'

 

In [41]: raw2.decode('utf-16')

Out[41]: 'ëmail'

 

In [42]: raw.decode('utf-16')

Out[42]: 'ꯃ慭汩'

 

'Python > string' 카테고리의 다른 글

format string  (0) 2019.12.27
반복되는 문자열 찾기  (0) 2019.12.27
append, pop, sort, reverse  (0) 2019.12.27
encode, decode  (0) 2019.12.26
ascii, hex, unicode  (0) 2019.12.26

+ Recent posts