Fix encode filename issues python2

This commit is contained in:
tzutalin
2017-02-15 17:33:55 +08:00
parent afee5a4e95
commit 62507a1958
2 changed files with 28 additions and 29 deletions
+3 -4
View File
@@ -5,8 +5,7 @@ import sys
from xml.etree import ElementTree
from xml.etree.ElementTree import Element, SubElement
from lxml import etree
import codecs
import io
class PascalVocWriter:
@@ -101,9 +100,9 @@ class PascalVocWriter:
self.appendObjects(root)
out_file = None
if targetFile is None:
out_file = codecs.open(self.filename + '.xml', 'w', encoding='utf-8')
out_file = io.open(self.filename + '.xml', 'w', encoding='utf-8')
else:
out_file = codecs.open(targetFile, 'w', encoding='utf-8')
out_file = io.open(targetFile, 'w', encoding='utf-8')
prettifyResult = self.prettify(root)
out_file.write(prettifyResult.decode('utf8'))