Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
lines[0].startswith('-') solution in Clear category for YAML. List and Comments by flpo
const = {'': None, 'null': None, 'true': True, 'false': False}
def convert(value):
if value in const: return const[value]
if value[0] in '"\'':
return value[1:-1].encode('utf-8').decode('unicode_escape')
value = value.split('#')[0].strip()
return int(value) if value.isdigit() else value
def yaml(a):
lines = [l.strip() for l in a.splitlines() if l and not l.strip().startswith('#')]
if lines and lines[0].startswith('-'):
return [convert(l[2:]) for l in lines]
return {k: convert(v.strip()) for k, v in (l.split(':') for l in lines)}
Nov. 18, 2019
Comments: