make py2 unicode-handling py3-compatibe

This commit is contained in:
Ryan Flynn
2016-12-31 14:53:09 -05:00
parent 67a8583e22
commit c7ddf4a3ef
2 changed files with 39 additions and 25 deletions
+6 -2
View File
@@ -74,7 +74,11 @@ class PascalVocWriter:
for each_object in self.boxlist:
object_item = SubElement(top, 'object')
name = SubElement(object_item, 'name')
name.text = unicode(each_object['name'])
try:
name.text = unicode(each_object['name'])
except NameError:
# Py3: NameError: name 'unicode' is not defined
name.text = each_object['name']
pose = SubElement(object_item, 'pose')
pose.text = "Unspecified"
truncated = SubElement(object_item, 'truncated')
@@ -101,7 +105,7 @@ class PascalVocWriter:
out_file = open(targetFile, 'w')
prettifyResult = self.prettify(root)
out_file.write(prettifyResult)
out_file.write(prettifyResult.decode('utf8'))
out_file.close()