import yaml if __name__ == '__main__': stream = open("config_sim.yaml", 'r') # dictionary = yaml.load(stream) dictionary = yaml.load(stream, Loader=yaml.SafeLoader) # print(dictionary) for key, value in dictionary.items(): print (key + " : " + str(value)) with open("config_sim.yaml", "r") as stream: try: dictionary = yaml.safe_load(stream) for key, value in dictionary.items(): print (key + " : " + str(value)) except yaml.YAMLError as exc: print(exc)