Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x yaml.safe_load返回字符串而不是对象_Python 3.x_Pyyaml - Fatal编程技术网

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
   ...