我需要从python的嵌套关键字中提取出特定的值,例如从下面我想从关键字Params中提取出Start
{'Key': 'Params', 'Value': `'{"Shut":false,"Remove":false,"SnapshotRequired":false,"Start":"Never","End":"Never"}'}这是我得到的
for tag in i["Tags"]: if 'Params' in tag['Key']:那么我可以获得价值,但这是整个字符串。
I need to extract out a specific value from within a nested key in python for example from the below I want to extract out the Start from the key Params
{'Key': 'Params', 'Value': `'{"Shut":false,"Remove":false,"SnapshotRequired":false,"Start":"Never","End":"Never"}'}This is as far as I have got
for tag in i["Tags"]: if 'Params' in tag['Key']:then I can get the value but this is the whole string.
最满意答案
您可以使用dict.get(key)方法获取您在get()指定的键的值,其中dict是存储字典的变量。
你也可以使用dict[key] 。 它给出了相同的结果。
例如,在你的情况下, dict['Key']将返回'Params', dict['Value']将返回嵌套字典。
You can use dict.get(key) method to get a value of the key you specify in get(), where dict is variable which stores your dictionary.
Also you can use dict[key]. It gives the same result.
In your case, for example, dict['Key'] will return 'Params', dict['Value'] will return nested dictionary.
更多推荐
发布评论