web-automation-demo/Library/Yaml.py

15 lines
431 B
Python
Raw Permalink Normal View History

2023-03-13 18:49:49 +08:00
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}})))