Python 3.x 使用python格式时出现KeyError错误
我是python新手,在尝试运行代码时遇到了这个错误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' 我知道也有类似的
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)