miércoles, 25 de julio de 2018

Receta Python 3 No. 6-4: Lectura Efeciente de un Documento XML Grande

1. Problema

Leer y manipular un documento XML de tamaño de manera eficiente, es decir, usando la menor cantidad de memoria de trabajo posible.

2. Solución

Para resolver este problema de procesamiento de datos incrementales, se ha de recurrir al uso de iteradores y generadores.

La clase xml.etree.ElementTree cuenta con la función iterparse() para el recorrido eficiente de un documento XML (Beazly, Jones, 2013).

3. Código Python 3

Archivo Python recorrido-eficiente-xml.py [enlace alternativo]:

Prueba de ejecución:


Open
Completed
Completed
Completed
Completed
Completed
Completed
Completed
Completed
Completed
Completed
Open
Open
Open
Open
Open
Open
Open
Open
Open
Open
Open
Open
Open
Open
Open
Open
Open
Completed
Completed
Completed
Completed
Completed
Open
Completed
Completed
Completed
Completed
Completed
Completed
Open
Completed
Completed
Open
Open
Completed
Completed
Open
Open
Open
Open
Completed
Open
Completed
Completed
Completed
Completed
Open
Completed
Open
Completed
Completed
Completed
Open
Completed
Completed
Open
Completed
Open
Open
Open
Open
Open
Open
Open
Completed
Completed
Completed
Completed
Completed
Completed
Completed
Completed
Completed
Completed
Completed
Completed
Completed
Completed
Completed
Completed
Open
Completed
Completed
Completed
Completed
Completed
Completed
Completed

Completed

4. Literatura & Enlaces

Beazly D, Jones B. K. (2013). Python Cookbook, Third Edition. United States: O'Reilly Media.

O

No hay comentarios:

Publicar un comentario

Envíe sus comentarios, dudas, sugerencias, críticas. Gracias.