迭代输出

时间:2016-11-14 15:09:47

标签: python

我想从python中access_key的下面输出中获取accessKey的值。 请告诉我如何迭代它并获得accessKey = ABCDEFGHIJ的值。

access_key = [SIM_IdentityOption(
identity=SIM_Identity(displayName='system-3b07c9ab-e049-42cf-b447-d1895c799dcd',
                      creationTime=1478611077.671846,
                      identityType=0,
                      enabled=True,
                      canonicalId='805821d085f1de0860dccdd5c8',
                      modificationTime=1478611077.734763,
                      apiKeys=[SIM_ApiKey(secretKey=None, creationTime=1478611077.73346, accessKey='ABCDEFGHIJ', enabled=True)],
                      email='system@internal.amplidata.com',
                      parentAccountCanonicalId=None))
          ]

2 个答案:

答案 0 :(得分:0)

这有效 -

access_key[0].identity.apiKeys[0].accessKey

答案 1 :(得分:0)

output = """[SIM_IdentityOption(
identity=SIM_Identity(displayName='system-3b07c9ab-e049-42cf-b447-d1895c799dcd',
                      creationTime=1478611077.671846,
                      identityType=0,
                      enabled=True,
                      canonicalId='805821d085f1de0860dccdd5c8',
                      modificationTime=1478611077.734763,
                      apiKeys=[SIM_ApiKey(secretKey=None, creationTime=1478611077.73346, accessKey='ABCDEFGHIJ', enabled=True)],
                      email='system@internal.amplidata.com',
                      parentAccountCanonicalId=None))
          ]"""

code = 'accessKey=\''
startcode = output.find(code) + len('accessKey=\'')
endcode = output.find('\'', startcode+1)
accesskey = output[startcode:endcode]
print accesskey