Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Using ast.literal_eval solution in Clear category for YAML. More Types by erykcoapl
import ast
__special_values = {'true': True, 'false': False, 'null': None, '': None}
def __eval_yaml_value(value: str):
return int(value) if value.isdecimal() else __special_values.get(
value, ast.literal_eval(
value if value.startswith(('"', "'")) else f'"{value}"'
)
)
def yaml(a):
return {
key: __eval_yaml_value(value.removeprefix(' '))
for key, value in (line.split(':') for line in a.split('\n') if line)
}
March 14, 2021