001_023 Python 对Unicode数据编码并应用于XML和HTML

来源:互联网 发布:手机上写代码的软件php 编辑:程序博客网 时间:2024/06/05 19:59

代码如下:

#encoding=utf-8print '中国'#对Unicode数据编码并应用于XML和HTML#解决方案def encode_for_xml(udata,encoding='ascii'):    return udata.encode(encoding,'xmlcharrefreplace')print encode_for_xml(u'中国')

打印结果如下:

中国
中国

0 0