Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created January 27, 2018 02:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fhernd/f044724b2197c260135080f5336b1327 to your computer and use it in GitHub Desktop.
Save Fhernd/f044724b2197c260135080f5336b1327 to your computer and use it in GitHub Desktop.
Escribir un archivo XML con Python.
import xml.etree.ElementTree as ET
elemento_1 = ET.Element('SistemasOperativos')
elemento_hijo_1 = ET.SubElement(elemento_1, 'Windows')
elemento_hijo_2 = ET.SubElement(elemento_1, 'Linux')
elemento_hijo_3 = ET.SubElement(elemento_1, 'MacOS')
archivo = open('SistemasOperativos.xml', 'a')
archivo.write(ET.tostring(elemento_1, encoding='utf-8').decode('utf-8'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment