我对python完全陌生,正在尝试为工作编写脚本。以下是一个示例片段:
config.yml:
company1:
threshold: 3
alert:
alert1: 0
alert2: 0
company2:
threshold: 6
alert:
alert1: 1
alert2: 1
我的Python脚本:
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
目前,我得到一个错误:
BoxKeyError: "'Box' object has no attribute 'foo'"
非常感谢您的帮助
你的
ArrayList
存储了1
即numbers
的ArrayList
应该以String
格式存储数字你的arrayList应该像
ArrayList<String>
当您使用
equals
签入arraylist时,您可以将数字作为字符串添加等等
相关问题 更多 >
编程相关推荐