我想用以下代码做三件事。但是我刚接触python 3(和一般的python)。
这是到目前为止的代码:
import boto3
# Create an S3 client
s3 = boto3.client('s3')
# Call S3 to list current buckets
response = s3.list_buckets()
# Get a list of all bucket names from the response
buckets = [bucket["Name"] for bucket in response['Buckets']]
# Print out the bucket list
print("Bucket List: %s" % buckets)
这是上面代码的输出:
Bucket List: ['aws-ip-update-01', 'aws-ip-update-02', 'aws-ip-update-bucket', 'case4667772691-cloudtraillogs', 'cf-templates-10gcjonooe0lj-us-east-1', 'config-bucket-832839043616', 'fsaas', 'company-aws-config', 'company-cloudtrail-nonprod', 'company-dev', 'company-isam9', 'company-netbackup-nonprod', 'company-timd-test-bucket', 'kpmgimagedeploy', 'ussvcsplunkaws-nonprod-keys']
我该如何实现这三件事?
答案 0 :(得分:4)
使用列表分解和print
的{{1}}指示符将sep
放在每个元素打印图之间:
'\n'
输出:
data = ['aws-ip-update-01', 'aws-ip-update-02', 'aws-ip-update-bucket',
'case4667772691-cloudtraillogs', 'cf-templates-10gcjonooe0lj-us-east-1',
'config-bucket-832839043616', 'fsaas', 'company-aws-config',
'company-cloudtrail-nonprod', 'company-dev', 'company-isam9',
'company-netbackup-nonprod', 'company-timd-test-bucket', 'kpmgimagedeploy',
'ussvcsplunkaws-nonprod-keys']
print("Bucket List: ", *data, sep="\n")
Doku: