我正在尝试插入来自用户的两个变量& json有效负载中的文本文件。但是我得到了关键错误
代码
print ('{"ip-address": "x.x.x.x","user-name": "john","password": "{}","db-name": "{}","service-name": "Sql","port": #"000","connection-string": "xxx"}'.format(Pass,x.strip()))错误
KeyError: '"ip-address"'发布于 2019-07-02 13:48:44
在使用.format()或f-字符串时,您需要更加小心地使用大括号。离开一个{或}会被误解。如果要在使用{或f-字符串时打印单个.format(),则需要添加{{。
例如:
name = 'foo'
print(f'{name} }')给出语法错误。但是:
name = 'foo'
print(f'{name} }}')给出所需的输出:>>> foo }。
https://stackoverflow.com/questions/56853616
复制相似问题