Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.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 使用python格式时出现KeyError错误_Python 3.x_String_Format - Fatal编程技术网

Python 3.x 使用python格式时出现KeyError错误

Python 3.x 使用python格式时出现KeyError错误,python-3.x,string,format,Python 3.x,String,Format,我是python新手,在尝试运行代码时遇到了这个错误 KeyError Traceback (most recent call last) <ipython-input-201-74e7a7ea82f3> in <module> ----> 1 SEARCH['profession']['call'].format('Jhon',23) KeyError: '"sea' 我知道也有类似的

我是python新手,在尝试运行代码时遇到了这个错误

KeyError                                  Traceback (most recent call last)
<ipython-input-201-74e7a7ea82f3> in <module>
----> 1 SEARCH['profession']['call'].format('Jhon',23)

KeyError: '"sea'

我知道也有类似的问题,但我还没有找到解决方案

其他的花括号对于替换字段是混淆的,因此您应该更改您正在使用的字符串格式方法(例如或C样式格式)。您是否控制
搜索
?如果您这样做,我会将其用作完整嵌套的
dict
,然后在需要文本时,在我需要的任何部分上使用
json.dumps()
SEARCH = {
    'profession' : {"call":'{"sea:searchProfession":{"datasheet": {"name":{},"age": {}}}}'},
    'id' : {"call":'{"sea:searchId":{"personId": {"id":{},"name": {},"age":"{}"}}}'},
}

SEARCH['profession']['call'].format('Jhon',23)