问题描述
"clone": [
{
"href": "http://abc.compute.amazonaws.com:7990/scm/fin/test.git","name": "http",},{
"href": "ssh://git@abc.compute.amazonaws.com:7999/fin/test.git","name": "ssh",]
我有一个带有两个随机移动的对象的数组,如何使用python引用名称(保持静态),从而在第一个对象内提取 href 值boto3。
解决方法
您可以进行线性搜索:
href = next(x for x in array if x['name']=='ssh')['href']
如果您的array
没有匹配name
的字典/对象,则会抛出异常。