Writing bytes to file, bad encoding
I have a problem in Python 3.x with writing to file, write function in FOR
is writing czech signs in utf-8 coding. I am new in Python but i set up
IDE and .py, .xml files for 'utf-8' encoding and i have no idea why is
output file looking like that. My code:
-*- coding: utf-8 -*-
from lxml import etree
from io import BytesIO
import sys
import codecs
f = open('uzivatelska_prirucka.xml','rb')
fo = open('try.xml','wb',1)
header = '?xml version="1.0" encoding="utf-8"?>\n<root\n'
fo.write(bytes(header,'UTF-8'))
some_file_like_object = f
tree = etree.parse(some_file_like_object)
root = tree.getroot()
node = tree.xpath('/prirucka/body/p');
for a in node:
for b in a.getiterator():
if not (b.find('r') is None):
text = etree.tostring(b.find('r'))
fo.write(bytes(str(text),'UTF-8'))
Thanks for your help and advices
No comments:
Post a Comment