Created
May 29, 2015 18:42
-
-
Save jgomo3/7787d84fd8d15c4291f8 to your computer and use it in GitHub Desktop.
One YML to CSV merging keys and values in rows.
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
import yaml | |
import csv | |
from sys import stdout | |
salida = open('reglas.csv', 'w') | |
# salida = stdout | |
reglas = yaml.safe_load(open('reglas_de_negocio.yaml')) | |
campos = ['descripción', 'observaciones'] | |
tabla = [ | |
[nombre] + [regla.get(campo, '') for campo in campos] | |
for | |
nombre, regla in reglas.items() | |
] | |
table_writer = csv.writer(salida) | |
table_writer.writerow(['nombre'] + campos) | |
for row in tabla: | |
table_writer.writerow(row) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment