浅说 python 编码的转换
!/usr/bin/python2
# -*- coding:utf-8 -*-
temp = "猪"
#解码,需要指定原来是什么编码,解码成Unicode
temp_unicode = temp.decode('utf-8')
编码,由unicode编码成gbk
temp_gbk = temp_unicode.encode("gbk")
print(temp_gbk)
#!/usr/bin/python3
# -*- coding:utf-8 -*-
temp = "猪"
temp_gbk = temp.encode("gbk")
print(temp_gbk)