我已经成功安装了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
答案 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)