【发布时间】:2015-01-31 18:12:49
【问题描述】:
在answer 中,描述了如何使用 python 编辑 yaml 文件的特定条目。我尝试使用以下 yaml 文件的代码
- fields: {domain: "www.mydomain.com", name: "www.mydomain.com"}
model: sites.site
pk: 1
但有
with open('my.yaml', 'r') as f:
doc = yaml.load(f)
txt = doc["fields"]["domain"]
print txt
我得到了错误
Traceback (most recent call last):
File "./test.py", line 9, in <module>
txt = doc["fields"]["domain"]
TypeError: list indices must be integers, not str
现在,我想我可以在 doc.. 上使用密钥。有人可以帮助我吗? :)
【问题讨论】:
标签: python