将所有列表项添加到字符串python

时间:2017-09-11 07:33:29

标签: python-3.6

我有一份清单 "SecretList"["GitHubToken","GitHubUser"]

def handler(event, context):                 
    response_data = {}
    try:
        param = " "
        param_value = [event['SecretList']]
        for i in range(len(param_value)):
            param[i] = “ “.join(map(str, param_value[1])
            value = get_parameters(param[i])
            print (value)

    except Exception as e:
        print (e)

需要单独字符串中的列表项

str1=GitHubToken
str2=GitHubUser

我的逻辑不起作用,有人可以建议我吗

2 个答案:

答案 0 :(得分:0)

def handler(event, context):                 
    response_data = {}
    try:
        param = {}
        param_value = event['SecretList']
        for index, value in enumerate(param_value):
             param.update({'str{}'.format(index): value})
        print param  #output:  {'str1': 'GitHubUser', 'str0': 'GitHubToken'}

    except Exception as e:
        print (e)

答案 1 :(得分:0)

我使用了以下逻辑:

def handler(event, context):                 
response_data = {}
try:
    param = {}
    param_value = event['SecretList']
    for idx, item in enumerate(param_value):
        print (idx)
        value = get_parameters(param_value[idx])
        print (value)

except Exception as e:
    print (e)