s3用python比较键

2024-09-30 02:19:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我有2个存储桶,其中包含以下文件:

freedom-meital3
\text4
\text5   
freedom-meital2
\text5
\text4

我只想在密钥相同的情况下比较etag。我弄错语法了。问题在于:if key['Key'] == key2['Key']

 conn = client('s3')  # again assumes boto.cfg setup, assume AWS S3
    for key2 in conn.list_objects(Bucket='freedom-meital3')['Contents']:
        for key in conn.list_objects(Bucket='freedom-meital2')['Contents']:
            print(key2['Key'])
            print(key['Key'])
            if key['Key'] == key2['Key']

Tags: keyinforifobjectsbucketconnlist
1条回答
网友
1楼 · 发布于 2024-09-30 02:19:52

if语句的计算结果为true时,您想做什么?这没有被处理,您在它后面也丢失了一个:。可能是这样的:

 conn = client('s3')  # again assumes boto.cfg setup, assume AWS S3
    for key2 in conn.list_objects(Bucket='freedom-meital3')['Contents']:
        for key in conn.list_objects(Bucket='freedom-meital2')['Contents']:
            if key['Key'] == key2['Key']:
                print(key2['Key'])
                print(key['Key'])

相关问题 更多 >

    热门问题