Use unicode as predicate in xpath with lxml and python 2.7 -
i've been facing problem have xml file unicode strings , need evaluate xpath on it, through lxml in python-2.7.
# -*- coding: utf-8 -*- 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")
gives error: unicodeencodeerror: 'ascii' codec can't encode character u'\xe5' in position 14: ordinal not in range(128)
stop mixing them.
xpath = u"//language[./description = '{}']//description/text()".format(description)
Comments
Post a Comment