Python版本3.5
我正在尝试进行API调用以使用json作为格式配置设备.一些json会根据所需的命名而有所不同,所以我需要在字符串中调用一个变量.我可以使用旧样式完成此操作%s... % (variable),但不能使用新样式{}... .format(variable).
EX失败:
(Testing with {"fvAp":{"attributes":{"name":(variable)}}})
a = "\"app-name\""
app_config = ''' { "fvAp": { "attributes": { "name": {} }, "children": [ { "fvAEPg": { "attributes": { "name": "app" }, "children": [ { "fvRsBd": { "attributes": { "tnFvBDName": "default" }, } } ] } }, { "fvAEPg": { "attributes": { "name": "db" }, "children": [ { "fvRsBd": { "attributes": { "tnFvBDName": "default" }, } } ] } } ] } } '''.format(a)
print(app_config) …Run Code Online (Sandbox Code Playgroud)