I\'m sorry, I know very little of both YAML and PyYAML but I felt in love with the idea of supporting a configuration file written in the same style used by \"Jekyll\" (http
The Python yaml
library does not support reading yaml that is embedded in a document. Here is a utility function that extracts the yaml text, so you can parse it before reading the remainder of the file:
#!/usr/bin/python2.7
import yaml
import sys
def get_yaml(f):
pointer = f.tell()
if f.readline() != '---\n':
f.seek(pointer)
return ''
readline = iter(f.readline, '')
readline = iter(readline.next, '---\n')
return ''.join(readline)
for filename in sys.argv[1:]:
with open(filename) as f:
config = yaml.load(get_yaml(f))
text = f.read()
print "TEXT from", filename
print text
print "CONFIG from", filename
print config