使用Python3和ElementTree生成.SVG文件时出现问题.
from xml.etree import ElementTree as et
doc = et.Element('svg', width='480', height='360', version='1.1', xmlns='http://www.w3.org/2000/svg')
#Doing things with et and doc
f = open('sample.svg', 'w')
f.write('<?xml version=\"1.0\" standalone=\"no\"?>\n')
f.write('<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n')
f.write('\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n')
f.write(et.tostring(doc))
f.close()
Run Code Online (Sandbox Code Playgroud)
Function et.tostring(doc)生成TypeError"write()参数必须是str,而不是bytes".我不明白这种行为,"et"应该将ElementTree-Element转换为字符串?它适用于python2,但不适用于python3.我做错了什么?