尝试获取 YAML 文档以解析为我可以操作的 python 字典对象。我安装了 pip install pyyaml
。
import yaml
yamlstring = "some: var \n another: 3"
type(yaml.load(yamlstring))
>> str
令我惊讶的是它返回的是一个字符串而不是字典!我在这里做错了什么?
最佳答案
空格过多。
>>> import yaml
>>> yamlstring = "some: var\nanother: 3"
>>> type(yaml.load(yamlstring))
dict
关于python:PyYAML 模块未解析为对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32827695/