栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何使用boto3将S3对象保存到文件

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何使用boto3将S3对象保存到文件

Boto3最近有一项自定义功能,可以帮助您(其中包括其他方面)。它当前在低级S3客户端上公开,可以这样使用:

s3_client = boto3.client('s3')open('hello.txt').write('Hello, world!')# Upload the file to S3s3_client.upload_file('hello.txt', 'MyBucket', 'hello-remote.txt')# Download the file from S3s3_client.download_file('MyBucket', 'hello-remote.txt', 'hello2.txt')print(open('hello2.txt').read())

这些功能将自动处理读取/写入文件,以及并行并行处理大文件。

请注意,

s3_client.download_file
这不会创建目录。可以将其创建为
pathlib.Path('/path/to/file.txt').parent.mkdir(parents=True,exist_ok=True)



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/455695.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号