yml2dict.py 445 B

1234567891011121314151617181920212223
  1. #!/user/bin/env python
  2. # coding=utf-8
  3. """
  4. Read YAML file and convert it to a python dictionary.
  5. @author: yannansu
  6. @created at: 19.03.21 21:53
  7. """
  8. import yaml
  9. def yml2dict(file_path):
  10. """
  11. Load and read a YAML file.
  12. :param file_path: YAML file path
  13. :return: a dictionary converted from YAML
  14. """
  15. with open(file_path) as file:
  16. par_dict = yaml.load(file, Loader=yaml.FullLoader)
  17. return par_dict