yaml_test.py 775 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/usr/bin/env python
  2. # -*- encoding: utf-8 -*-
  3. """
  4. @Contact : liuyuqi.gov@msn.cn
  5. @Time : 2024/04/30
  6. @License : Copyright © 2017-2022 liuyuqi. All Rights Reserved.
  7. @Desc : yaml read and write
  8. """
  9. import yaml
  10. def read_yaml(file_path):
  11. with open(file_path, 'r') as file:
  12. data = yaml.load(file, Loader=yaml.FullLoader)
  13. return data
  14. def write_yaml(file_path, data):
  15. with open(file_path, 'w') as file:
  16. yaml.dump(data, file)
  17. if __name__=='__main__':
  18. data = {
  19. "owner": "xx",
  20. "token": "xx",
  21. "repo": "xx",
  22. "secret": [
  23. {
  24. "key": "xx",
  25. "value": "xx"
  26. },
  27. {
  28. "key": "x",
  29. "value": "xx"
  30. }
  31. ]
  32. }
  33. write_yaml("account.example.yml", data)