问题1:python split中文符号时报错
weatherDict["maxWendu"]=int(weatherDict["maxWendu"].split("(")[0])
UnicodeDecodeError: 'ascii' codec can't decode byte 0xef in position 0: ordinal not in range(128)
已添加
#!/usr/bin/env python
#coding=utf-8
1.
对需要 str->unicode 的代码,可以在前边写上
import sys
reload(sys)
sys.setdefaultencoding(‘utf8′)
把 str 编码由 ascii 改为 utf8 (或 gb18030)
2.
python3 区分了 unicode str 和 byte arrary,并且默认编码不再是 ascii
当字符串是:'\u4e2d\u56fd'
>>>s=['\u4e2d\u56fd','\u6e05\u534e\u5927\u5b66']
>>>str=s[0].decode('unicode_escape') #.encode("EUC_KR")
>>>print str
中国
js处理'\u4e2d\u56fd' :
http://www.codefans.net/jscss/code/4794.shtml
var classObj=
{
ToUnicode:function(str)
{
return escape(str).replace(/%/g,"\\").toLowerCase();
},
UnUnicode:function(str)
{
return unescape(str.replace(/\\/g, "%"));
},
}
当字符串是:' 东亚学团一中'
>>>print unichr(19996)
东
ord()支持unicode,可以显示特定字符的unicode号码,如:
>>>print ord('A') 65
只要和Unicode连接,就会产生Unicode字串。如:
>>> 'help' 'help' >>> 'help,' + u'python' u'help,python'
对于ASCII(7位)兼容的字串,可和内置的str()函数把Unicode字串转换成ASCII字串。如:
>>> str(u'hello world') 'hello world'