Created
July 26, 2018 12:40
-
-
Save Fhernd/c68500ec3ac622bf6991347ec0a684f2 to your computer and use it in GitHub Desktop.
Conversión de un diccionario en un elemento XML en Python. OrtizOL.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from xml.etree.ElementTree import Element | |
def diccionario_a_xml(etiqueta, diccionario): | |
elemento = Element(etiqueta) | |
for k, v in diccionario.items(): | |
hijo = Element(k) | |
hijo.text = str(v) | |
elemento.append(hijo) | |
return elemento | |
datos = { | |
'lenguaje': 'Python', | |
'version': '3.6.4', | |
'creator': 'Guido van Rossum' | |
} | |
elemento = diccionario_a_xml('programacion', datos) | |
print(elemento) | |
print(elemento[0].text) | |
print(elemento[1].text) | |
print(elemento[2].text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment