Python 3.x yaml.safe_load返回字符串而不是对象
我有一段代码:Python 3.x yaml.safe_load返回字符串而不是对象,python-3.x,pyyaml,Python 3.x,Pyyaml,我有一段代码: config_object = yaml.safe_load(config_string) print("passed config: {}".format(config_object)) ^^ prints expected yaml structure print("deserialized config object type: {}".format(type(config_object)))
config_object = yaml.safe_load(config_string)
print("passed config: {}".format(config_object))
^^ prints expected yaml structure
print("deserialized config object type: {}".format(type(config_object)))
^^ prints deserialized config object type: <class 'str'>
value = config_object["field1"]["field2"]["field3"]
^^ Error: string indices must be integers
我不明白为什么字符串被返回。我在这里看不到任何字符串返回类型:您的示例对我适用:您的示例对我适用:
---
field1:
field2:
field3: value
field4: value
...