15 lines
431 B
Python
15 lines
431 B
Python
|
import yaml
|
||
|
|
||
|
|
||
|
def yaml_encode(data, indent=None, unicode=False):
|
||
|
return yaml.dump(data, indent=indent, allow_unicode=not unicode, sort_keys=False)
|
||
|
|
||
|
|
||
|
def yaml_decode(data):
|
||
|
return yaml.load(data, Loader=yaml.CFullLoader)
|
||
|
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
# e.g. Yaml encoding and decoding it.
|
||
|
print(yaml_decode(yaml_encode({"id": 101, "name": "Tom", "friends": ["Tony", "Jason"], "score": {"english": 92, "math": 61}})))
|