test_yaml.py 556 Bytes
Newer Older
Fang Yuedong's avatar
Fang Yuedong committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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)