- 首页 > it技术 > >
Python|Python 遍历中国区 s3 目录(qbit)
Python 3.9
s3fs2021.7.0
- s3fs 文档:https://s3fs.readthedocs.io/
- client_kwargs 参见:https://botocore.amazonaws.co...
- 示例代码
# coding: utf-8
# author: qbit
# date: 2021-08-08
# summary: 遍历中国区 S3 目录import s3fs# 如果操作系统已配置命令行可访问 s3
# 可以不用参数
fs = s3fs.S3FileSystem(
key="aws_access_key_id",
secret="aws_secret_access_key",
client_kwargs={"region_name": "cn-northwest-1"}# 中国宁夏区
)print(fs.ls("qbit-cn-northwest-1"))
for parent, dirs, files in fs.walk("qbit-cn-northwest-1/data"):
for file in files:
pathfile = f"{parent}/{file}"
print(f"{fs.size(pathfile)/1024:8.2f} KB {pathfile}")
本文出自
qbit snap
推荐阅读