我遇到的问题是我有一个带Unicode字符串的XML文件,需要通过Python-2.7中的lxml对其求值一个Xpath。
# -*- coding: utf-8 -*-
from lxml import etree
...
class Language:
description = None
def __init__(self, description):
xpath = "//language[./description = '{}']//description/text()".format(description)
self.description= lang_xml.xpath(xpath)
...
lang = Language(u"Norwegian Bokmål")
给出错误: UnicodeEncodeError: 'ascii' codec can't encode character u'\xe5' in position 14: ordinal not in range(128)
停止混合它们。
xpath = u"//language[./description = '{}']//description/text()".format(description)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句