I am completely new to python and trying to write a script for work. Here is a sample snippet:
config.yml:
company1:
threshold: 3
alert:
alert1: 0
alert2: 0
company2:
threshold: 6
alert:
alert1: 1
alert2: 1
My Python script:
import yaml
from box import Box
with open("config.yml", 'r') as open_file:
try:
cfg = Box(yaml.safe_load(open_file))
except yaml.YAMLError as err:
print(err)
def myDef(foo):
t = cfg.foo.threshold
a1 = cfg.foo.alert.alert1
return t, a1
v = myDef("company1")
print(v[0])
#desired result: 3
x = myDef("company2")
print(x[1])
#desired result: 1
Currently, I get an error:
BoxKeyError: "'Box' object has no attribute 'foo'"
Any help is much appreciated.