【问题标题】:Parse a variable to a key in python将变量解析为python中的键
【发布时间】:2020-07-21 14:47:04
【问题描述】:

我是 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"]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-04
      • 2019-12-15
      • 2019-05-30
      • 2015-05-10
      • 1970-01-01
      • 2020-03-31
      相关资源
      最近更新 更多