10 examples of 'read yaml file python' in Python

Every line of 'read yaml file python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
14def read_file(self, file):
15 with open(file, 'r') as f:
16 return yaml.load(f)
91def read_yaml_file(filename: Text) -> Dict[Text, Any]:
92 """Parses a yaml file.
93
94 Args:
95 filename: The path to the file which should be read.
96 """
97 return read_yaml(read_file(filename, "utf-8"))
150def load_configfile(yaml_file: str) -> Dict:
151 with open(yaml_file, 'r') as conf:
152 return yaml.load(conf, MyLoader)
20def read_yaml_file(full_file_path):
21 """Read and parse yaml file.
22
23 Args:
24 full_file_path (str): The full file path.
25 """
26 with open(full_file_path, 'r') as f:
27 try:
28 return yaml.safe_load(f)
29 except yaml.YAMLError as yaml_error:
30 raise yaml_error
32def load_yaml(file_path):
33 string = get_file_contents(file_path)
34 return yaml.load(str(string))
12def parse_yaml(yaml_file):
13 """
14 Parses a yaml file, returning its contents as a dict.
15 """
16
17 try:
18 import yaml
19 except ImportError:
20 sys.exit("Unable to import yaml module.")
21
22 try:
23 with io.open(yaml_file, encoding="utf-8") as fname:
24 return yaml.load(fname)
25 except IOError:
26 sys.exit("Unable to open YAML file: {0}".format(yaml_file))
46def load_yaml(yaml_file_path):
47 """
48 Loads a YAML file as a in-memory dictionary
49 """
50 with open(yaml_file_path) as yaml_file:
51 yaml_config = yaml.load(yaml_file)
52 return yaml_config
30def read_yaml(path):
31 """
32 Yaml Reader method
33 Parameters
34 ----------
35 str path: path of file
36 """
37 try:
38 with open(path, "r") as config:
39 try:
40 return yaml.safe_load(config)
41 except yaml.YAMLError as exc:
42 return None
43 except IOError as io_err:
44 return None
26def read_yaml(config_file_path):
27 """
28 Reads the yaml file and returns a dictionary object
29 :param config_file_path: The file path of config in yaml
30 :return: a dictionary
31 """
32 logger.debug('Loading configuration file - ' + config_file_path)
33 with open(config_file_path) as config_file:
34 config = yaml.safe_load(config_file)
35 logger.info('Configuration Loaded')
36 config_file.close()
37 logger.info('Closing config file')
38 return config
132def _load_yaml_file(file_name: str) -> Any:
133 """
134 Load the yaml file and returns the python object.
135
136 Args:
137 file_name: name of the .yml file
138
139 Returns:
140 Contents of the yml file deserialized into a Python object
141
142 Raises:
143 LoadConfigError: on error
144 """
145
146 try:
147 with open(file_name, 'r') as stream:
148 data = yaml.safe_load(stream)
149 return data
150 except (OSError, yaml.YAMLError) as e:
151 raise LoadConfigError('Error loading yml config') from e

Related snippets