使用Python从S3存储桶中读取.txt文件并查看其内容的步骤如下:
import boto3
s3_client = boto3.client('s3')
bucket_name = 'your_bucket_name'
file_key = 'path/to/your_file.txt'
local_file_path = '/tmp/your_file.txt'
s3_client.download_file(bucket_name, file_key, local_file_path)
with open(local_file_path, 'r') as file:
file_content = file.read()
print(file_content)
完整代码示例:
import boto3
s3_client = boto3.client('s3')
bucket_name = 'your_bucket_name'
file_key = 'path/to/your_file.txt'
local_file_path = '/tmp/your_file.txt'
s3_client.download_file(bucket_name, file_key, local_file_path)
with open(local_file_path, 'r') as file:
file_content = file.read()
print(file_content)
这样就可以使用Python从S3存储桶中读取.txt文件并查看其内容了。
推荐的腾讯云相关产品:腾讯云对象存储(COS)
领取专属 10元无门槛券
手把手带您无忧上云