test_config.py 840 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import yaml
  2. test_data = {
  3. 'cameras': [{
  4. 'id': 1,
  5. 'ip': "192.168.1.2"
  6. }, {
  7. 'id': 2,
  8. 'ip': "192.168.1.3"
  9. }]
  10. }
  11. def read_yaml(path):
  12. try:
  13. with open(path, 'r') as file:
  14. data = file.read()
  15. # result = yaml.load(data)
  16. result = yaml.load(data, Loader=yaml.FullLoader)
  17. return result
  18. except Exception as e:
  19. print(e)
  20. return None
  21. def write_yaml(path):
  22. try:
  23. with open('path', 'w', encoding='utf-8') as f:
  24. yaml.dump(data=test_data, stream=f, allow_unicode=True)
  25. except Exception as e:
  26. print(e)
  27. if __name__ == '__main__':
  28. p = 'train.yaml'
  29. result = read_yaml(p)
  30. # j=json.load(result)
  31. print('result', result)
  32. # print('cameras', result['cameras'])
  33. # print('json',j)