使用python

时间:2019-04-25 15:37:55

标签: python

我正在打印出AWS中的用户列表。根据第一列长度的变化,数据以不均匀的方式输出到屏幕上:

us-svc-cloudops-aws                           AIDAIDNRJABLEK6Z2MSME         arn:aws:iam::123456789101:user/us-svc-cloudops-aws      2019-02-13 19:05:10
us-svc-kadi-aws-jenkins                           AIDAJHPWXCPNWRU6UCRPO         arn:aws:iam::123456789101:user/us-svc-kadi-aws-jenkins      2017-05-16 18:35:11
us-svc-ksr                           AIDAIPXXXD3JW3A75QNR2         arn:aws:iam::123456789101:user/us-svc-ksr      2018-05-15 20:25:17
us-svc-splunk-aws                           AIDAINU7WJB4O3DHQXCLU         arn:aws:iam::123456789101:user/us-svc-splunk-aws      2017-10-03 15:40:59
us-svc-turbomonic-aws                           AIDAIRNXWR5BZOKJZ6TMU         arn:aws:iam::123456789101:user/us-svc-turbomonic-aws      2017-10-03 15:53:04

到目前为止,这是我的代码:

user_list = client.list_users()
for user in user_list['Users']:
    user_name = user['UserName']
    user_id = user['UserId']
    user_arn = user['Arn']
    create_date = user['CreateDate']
    time_format = "%Y-%m-%d %H:%M:%S"
    create_date = str(create_date.strftime(time_format))
    print_string = user_name + '           ' + user_id + '         ' + user_arn + '      ' + create_date
    print(print_string)

以下是user_list外观的示例:

{'Users': [{'Path': '/', 'UserName': 'bluethundr', 'UserId': 'AIDAVMGUQ5SMEMELAT4YR', 'Arn': 'arn:aws:iam::123456789101:user/bluethundr', 'CreateDate': datetime.datetime(2019, 4, 5, 16, 39, 1, tzinfo=tzutc())}], 'IsTruncated': False, 'ResponseMetadata': {'RequestId': '1ccacd69-5749-4284-a690-4a6de43f22f4', 'HTTPStatusCode': 200, 'HTTPHeaders': {'x-amzn-requestid': '1ccacd69-5749-4284-a690-4a6de43f22f4, 1ccacd69-5749-4284-a690-4a6de43f22f4', 'date': 'Thu, 25 Apr 2019 15:33:41 GMT', 'content-type': 'text/xml', 'content-length': '557'}, 'RetryAttempts': 0}}

我希望屏幕上的输出均匀分布。有什么办法可以使用python实现此目的吗?

0 个答案:

没有答案