错误情况:UnicodeEncodeError: 'ascii' codec can't encode characters in position······
指定一个字条串为unicode编码
str = u'你好,hello'
判断字条串是否为unicode
isinstance(str, unicode)
字符串str为unicode码时
str.encode('utf-8') #这样就可以转换成utf-8编码了
要进行编码转换,都需要先用decode方法将其转换成unicode编码,再使用encode方法将其转换成其他编码。
注:http://www.jb51.net/article/17560.htm
注:这是python2.7,在python3中不适用