在烧瓶中导入YAML

时间:2018-12-04 05:51:03

标签: python flask yaml

我已经成功安装了PyYAML:

 (venv) D:\myproject>python app.py
 Traceback (most recent call last):
 File "app.py", line 7, in <module>
 db=yaml.load(open['db.yaml'])
  TypeError: 'builtin_function_or_method' object is not subscriptable

2 个答案:

答案 0 :(得分:1)

open是可调用的内置文件,不可下标(您无法通过[]访问项目)。我认为您想要调用它,例如:

db=yaml.load(open('db.yaml'))

答案 1 :(得分:0)

我认为您需要执行以下操作。

import yaml

with open("db.yaml", 'r') as stream:
    try:
        print(yaml.load(stream)) # or do something else with it
    except yaml.YAMLError as exc:
        print(exc)