我有一本字典,我需要找到一个键的值。以下命令未返回预期值“mar5-deliveryreport-new”
>>> mydict['ClusterIdentifier']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: 'ClusterIdentifier'
>>> mydict
{u'DescribeClustersResponse': {u'DescribeClustersResult': {u'Marker': None, u'Clusters': [{u'PubliclyAccessible': True, u'MasterUsername': u'root', u'VpcSecurityGroups': [], u'ModifyStatus': None, u'NumberOfNodes': 1, u'PendingModifiedValues': {u'NodeType': None, u'ClusterType': None, u'MasterUserPassword': None, u'AutomatedSnapshotRetentionPeriod': None, u'ClusterVersion': None, u'NumberOfNodes': None}, u'VpcId': None, u'ClusterVersion': u'1.0', u'AutomatedSnapshotRetentionPeriod': 1, u'ClusterParameterGroups': [{u'ParameterApplyStatus': u'in-sync', u'ParameterGroupName': u'default.redshift-1.0'}], u'DBName': u'mydb', u'PreferredMaintenanceWindow': u'tue:08:00-tue:08:30', u'Endpoint': {u'Port': 5439, u'Address': u'mar5-deliveryreport-new.lc.us-east-1.redshift.amazonaws.com'}, u'RestoreStatus': {u'Status': u'completed', u'ProgressInMegaBytes': 804307, u'CurrentRestoreRateInMegaBytesPerSecond': 57.3072319201995, u'EstimatedTimeToCompletionInSeconds': 0, u'ElapsedTimeInSeconds': 14035, u'SnapshotSizeInMegaBytes': 804307}, u'AllowVersionUpgrade': True, u'ClusterCreateTime': 1381812358.833, u'ClusterSubnetGroupName': None, u'ClusterSecurityGroups': [{u'Status': u'active', u'ClusterSecurityGroupName': u'default'}], u'ClusterIdentifier': u'mar5-deliveryreport-new', u'AvailabilityZone': u'us-east-1a', u'NodeType': u'dw.hs1.xlarge', u'Encrypted': False, u'ClusterStatus': u'available'}]}, u'ResponseMetadata': {u'RequestId': u'233f495b-3576-11e3-83ff-d332123c25c4'}}}
>>> type(mydict)
<type 'dict'>