Skip to content

Instantly share code, notes, and snippets.

@jgomo3
Created May 29, 2015 18:42
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 jgomo3/7787d84fd8d15c4291f8 to your computer and use it in GitHub Desktop.
Save jgomo3/7787d84fd8d15c4291f8 to your computer and use it in GitHub Desktop.
One YML to CSV merging keys and values in rows.
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