python - UnicodeEncodeError: 'ascii' codec can't encode character u'\xe4' in position 7: ordinal not in range(128) -
i guess error coming fact xml file in utf-8, python wants handle ascii? have parsed xml correctly when try print contents of xml error because there foreign unicode characters. can try fix code below? may encode unicode string ascii? thanks!!
import xml.etree.elementtree et import sys if __name__ == '__main__': tree = et.parse('/downloads/sample.xml') root = tree.getroot() a=[] child in root.iter(): if child.tag == "author": a.append(child.text) if child.tag == "title": name in a: print "%s\t%s" % (name, child.text) a=[]
Comments
Post a Comment