python类型转换问题
>>> import sys
>>> print sys.getdefaultencoding()
ascii
>>> s = u'我是中国人'
>>> s
u'\xce\xd2\xca\xc7\xd6\xd0\xb9\xfa\xc8\xcb'#这是什么编码?
>>> print s
?òê??D1úè? #乱码?why?
>>> type(s)
<type 'unicode'>
>>> print s.encode('utf-8')
脦脪脢脟脰脨鹿煤脠脣 #乱码?why?
>>> print s.encode('gb2312')
Traceback (most recent call last):
File "<pyshell#14>", line 1, in <module>
print s.encode('gb2312')
UnicodeEncodeError: 'gb2312' codec can't encode character u'\xce' in position 0: illegal multibyte sequence
>>> isinstance(s,unicode)
True
>>>