您的位置:首页 > 编程语言 > Python开发

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

2014-03-12 02:13 246 查看
代码如下:

#encoding=utf-8

print '中国'

#对Unicode数据编码并应用于XML和HTML

#解决方案
def encode_for_xml(udata,encoding='ascii'):
return udata.encode(encoding,'xmlcharrefreplace')

print encode_for_xml(u'中国')


打印结果如下:

中国

中国
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: