read_conf.py 577 B

1234567891011121314151617181920212223242526
  1. # -*- coding: utf-8 -*-
  2. # @Time : 2024/6/7
  3. # @Author : 魏志亮
  4. import yaml
  5. def yaml_conf(path, encoding='utf-8'):
  6. with open(path, 'r', encoding=encoding) as f:
  7. data = yaml.safe_load(f)
  8. return data
  9. def read_conf(dict_conf, col, default_value=None):
  10. if col in dict_conf:
  11. res = dict_conf[col]
  12. if res is None and default_value is not None:
  13. return default_value
  14. return res
  15. else:
  16. return default_value
  17. if __name__ == '__main__':
  18. from pprint import pprint
  19. pprint(yaml_conf("../../conf/db.yaml"))