如何替换具有多个变量的字典的值?

时间:2016-01-12 16:46:49

标签: python robotframework

“bootMode”:{“manageMode”:是的,“模式”:“UEFIOptimized”}

我想更改“mode”的值:“UEFIOptimized to”mode“:”UEFI“。

2 个答案:

答案 0 :(得分:3)

我假设你的代码是:

some_dict = { ..., "bootMode": {"manageMode": True, "mode": "UEFIOptimized"}, ... }

问题是您必须更改嵌套的dict值。这比你想象的容易。

sub_d = some_dict["bootMode"]  # the dictionary you want to change
sub_d["mode"]                  # the value you want to change
sub_d["mode"] = "UEFI"         # ...and how to change it.

总之,你有

some_dict["bootMode"]["mode"] = "UEFI"

答案 1 :(得分:1)

收藏集的Set To Dictionary关键字在此处很有用。 Set To Dictionary ${bootMode} mode UEFI