我有一个以这种方式构造的dict对象:
{'snapshots': [{'snapshot': 'test_2018.11.19', 'uuid': 'Lv1C02wIRYGIljr3S16eIQ', 'version_id': 5060699, 'version': '5.6.6', 'indices': ['cribiscom_x_mydocs_entries_201712'], 'state': 'SUCCESS', 'start_time': '2018-11-19T16:57:44.014Z', 'start_time_in_millis': 1542646664014, 'end_time': '2018-11-19T16:57:46.380Z', 'end_time_in_millis': 1542646666380, 'duration_in_millis': 2366, 'failures': [], 'shards': {'total': 3, 'failed':
0, 'successful': 3}}]}
我想获取ket state 的值,但是我不太了解如何做到这一点,因为'napshots 是一个字典,然后有一个组成部分宾语。 有人可以向我解释吗?
答案 0 :(得分:0)
这只是从字典访问值的问题。您可以这样做:
mydict = {'snapshots': [{'snapshot': 'test_2018.11.19', 'uuid':'Lv1C02wIRYGIljr3S16eIQ', 'version_id': 5060699, 'version': '5.6.6', 'indices': ['cribiscom_x_mydocs_entries_201712'], 'state': 'SUCCESS', 'start_time': '2018-11-19T16:57:44.014Z', 'start_time_in_millis': 1542646664014, 'end_time': '2018-11-19T16:57:46.380Z', 'end_time_in_millis': 1542646666380, 'duration_in_millis': 2366, 'failures': [], 'shards': {'total': 3, 'failed': 0, 'successful': 3}}]}
value = mydict['snapshots'][0]['state']