【问题标题】:Parse a variable to a key in python将变量解析为python中的键
【发布时间】:2025-12-29 12:05:11
【问题描述】:

我是 python 新手,正在尝试 JSON,在这里我试图从 JSON 中选择值(成员列表),但我有多个集群可以从中选择成员:

with open("/some/path/example.json") as js:
   dcJson=json.load(js)
   i=1
   print (dcJson["search"]["nodes"]["cluster{}"]["members"]).format(i)

如何编写一些东西以便调用将是 dcJson["search"]["nodes"]["cluster1"]["members"]

非常感谢!

【问题讨论】:

    标签: python json python-2.7


    【解决方案1】:
    dcJson["search"]["nodes"]["cluster{}".format(i)]["members"]
    

    【讨论】: