Python字符串的encode与decode研究心得乱码问题解决方法:为什么会报错UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)?本文就来研究一下这个问题。 字符串在Python内部的表示是 代码如下:#!/usr/bin/env python
导读Python字符串的encode与decode研究心得乱码问题解决方法:为什么会报错UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)?本文就来研究一下这个问题。 字符串在Python内部的表示是 代码如下:#!/usr/bin/env python
为什么会报错“UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)”?本文就来研究一下这个问题。
字符串在Python内部的表示是 代码如下:
#!/usr/bin/env python #coding=utf-8 s="中文"
if isinstance(s, unicode): #s=u"中文" print s.encode('gb2312') else: #s="中文" print s.decode('utf-8').encode('gb2312')
Python字符串的encode与decode研究心得乱码问题解决方法
Python字符串的encode与decode研究心得乱码问题解决方法:为什么会报错UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)?本文就来研究一下这个问题。 字符串在Python内部的表示是 代码如下:#!/usr/bin/env python