#utf-8与gbk转换 #bytes 和str 的转换

1 #!/user/bin/env python
2 # -*- coding:utf-8 -*-
3 
4 temp = "连接"
5 temp_unicode = temp.decode('utf-8')
6 temp_gbk =unicode.encode('gbk')
7 print(temp_gbk)
 1 #!/usr/bin/env python
 2 #bytes 和str 的转换
 3 a = "李璐"
 4 b1 = bytes(a,encoding='utf-8')
 5 print(b1)
 6 newa1 = str(b1,encoding='utf-8')
 7 print(newa1)
 8 b2 = bytes(a,encoding='gbk')
 9 print(b1)
10 newa2 = str(b2,encoding='gbk')
11 print(newa2)

 

 

posted @ 2016-12-23 17:08  失落的黎明  阅读(1733)  评论(0编辑  收藏  举报