如何在Python2.7中将元素树中的元素写入unicode字符串

如何在Python2.7中将元素树中的元素写入unicode字符串,python,python-2.7,unicode,Python,Python 2.7,Unicode,我有一个填充了XML文档的元素,我需要将其写入unicode字符串,因为它包含非ascii字符。它包含的非ascii字符为。在我遇到这个bug之前,脚本是这样写的: tempxml = ET.tostring(cdadoc).decode("utf8").replace("&lt;","<").replace("&gt;",">").replace("&amp;","&").replace("><",">\n<") tempx

我有一个填充了XML文档的元素,我需要将其写入unicode字符串,因为它包含非ascii字符。它包含的非ascii字符为。在我遇到这个bug之前,脚本是这样写的:

tempxml = ET.tostring(cdadoc).decode("utf8").replace("&lt;","<").replace("&gt;",">").replace("&amp;","&").replace("><",">\n<")

tempxml=ET.tostring(cdadoc).解码(“utf8”).替换(“,”).替换(“&;”,“&”).替换(“>\n\n请提供一个‘cdadoc’的示例。我不在保存它的计算机旁,无法从头开始重新创建。我将在周一提供一个示例。谢谢这是一个示例:问题:代码类型:ICD9代码:V85.41描述:体重指数40.0-44.9,成人描述:体重指数值:50单位:kg/m²。”
tempxml = ET.tostring(cdadoc, encoding='unicode_internal', method='xml')
test = ET.tostring(cdadoc, encoding='punycode', method='xml')
print(type(tempxml))
print(type(test))
tempxml = tempxml.replace(u"&lt;",u"<").replace(u"&gt;",u">").replace(u"&amp;",u"&").replace(u"><",u">\n<")