yaml2csv 332 B

1234567891011121314151617181920
  1. #!/usr/bin/python
  2. import sys
  3. import yaml
  4. def comma(x, y):
  5. if x:
  6. return '{0},{1}'.format(x, y)
  7. else:
  8. return str(y)
  9. def print_obj(obj, lead=''):
  10. if type(obj) == dict:
  11. for k in obj:
  12. print_obj(obj[k], comma(lead, k))
  13. else:
  14. print(comma(lead, obj))
  15. with open(sys.argv[1]) as f:
  16. print_obj(yaml.load(f))