python - Writing an Element to a file -


I am using ElementTree to create, parse, and modify XML files and objects . I am creating a tree like this:

  import xml.etree.ElementTree etree foo = etree.Element ("root") etree.SubElement (foo, "extra", {" Id ":" 50 "})  

Then, I want to write it in a file accordingly, I should use an ElementTree object for that , But how to do this Element

I tried

  e = etree.ElementTree (foo) e.write (filename)  

but it does not work:

Type error: your phone may be opened Should be opened with b

("binary") as the "id":
  import xml.etree.ElementTree: "50"}) E = F: e.write (f)  

or simply pass as open ('test.xml', 'wb') with etree.ElementTree (foo):

e.write ('test.xml') for a file name / path

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -