config_tool.py 545 B

12345678910111213141516171819202122
  1. import yaml
  2. def read_yaml(path='application.yaml'):
  3. try:
  4. with open(path, 'r') as file:
  5. data = file.read()
  6. # result = yaml.load(data)
  7. result = yaml.load(data, Loader=yaml.FullLoader)
  8. return result
  9. except Exception as e:
  10. print(e)
  11. return None
  12. def write_yaml(path='application.yaml', data=None):
  13. try:
  14. with open(path, 'w', encoding='utf-8') as f:
  15. yaml.dump(data=data, stream=f, allow_unicode=True)
  16. except Exception as e:
  17. print(e)