错误:
Traceback (most recent call last):
File "/tmp/s3list.py", line 9, in <module>
if exclude_paths not in key['Key']:
TypeError: 'in <string>' requires string as left operand, not tuple
脚本:
from boto3 import client
exclude_paths=('DC','A')
conn = client('s3')
for key in conn.list_objects(Bucket='my-bucket')['Contents']:
if exclude_paths not in key['Key']:
print(key['Key'])
只有一条路径可以工作,但是我需要让它与多条路径一起工作。
exclude_paths
是一个元组,而不是字符串。
所以不是你的
if exclude_paths not in key['Key']:
采用
if key['Key'] not in exclude_paths:
附录:
如果要打印的路径中的排除对象不是以字符串开头的,请exclude_paths
使用
if not key['Key'].startswith(exclude_paths):
而不是您的原始if
声明。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句