pyl*_*ner 9 python amazon-s3 amazon-web-services
我已连接到 Amazon S3,并尝试使用以下代码从多个存储桶中的 JSON 内容中检索数据。
但我必须只读取特定的 JSON 文件,而不是全部。我该怎么做?
代码:
for i in bucket:
try:
result = client.list_objects(Bucket=i,Prefix = 'PROCESSED_BY/FILE_JSON', Delimiter='/')
content_object = s3.Object(i, "PROCESSED_BY/FILE_JSON/?Account.json")
file_content = content_object.get()['Body'].read().decode('utf-8')
json_content = json.loads(file_content)
except KeyError:
pass
Run Code Online (Sandbox Code Playgroud)
桶结构示例。
test-eob/PROCESSED_BY/FILE_JSON/222-Account.json
test-eob/PROCESSED_BY/FILE_JSON/1212121-Account.json
test-eob/PROCESSED_BY/FILE_JSON/122-multi.json
test-eob/PROCESSED_BY/FILE_JSON/qwqwq-Account.json
test-eob/PROCESSED_BY/FILE_JSON/wqwqw-multi.json
Run Code Online (Sandbox Code Playgroud)
从上面的列表中,我只想读取 *-Account.json 文件。
我怎样才能做到这一点?
在Python中,有多种方法可以做到这一点。例如,检查'stringA' 是否在 'stringB' 中:
list1=['test-eob/PROCESSED_BY/FILE_JSON/222-Account.json',
'test-eob/PROCESSED_BY/FILE_JSON/1212121-Account.json',
'test-eob/PROCESSED_BY/FILE_JSON/122-multi.json',
'test-eob/PROCESSED_BY/FILE_JSON/qwqwq-Account.json',
'test-eob/PROCESSED_BY/FILE_JSON/wqwqw-multi.json',]
for i in list1:
if 'Account' in i:
print (i)
else:
pass
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1190 次 |
| 最近记录: |