Python变量未初始化

时间:2018-08-14 09:06:03

标签: python aws-lambda

我在Python中具有以下AWS Lambda函数:

def lambda_handler(event, context):

    # Code
    # ..
    # ..
    # ..
    # Code

    output = ' '

    for key in diff.keys():
        for value in diff[key]:
            output += "<br> Key: " + key + ", Value: " + value + "</br>"

    print output

每次运行函数时,output的值都会附加到上一次运行的值上,尽管它是用output = ' '初始化的。

例如,如果output的值是:

<br> Key: " + A + ", Value: " + 1 + "</br>
<br> Key: " + B + ", Value: " + 2 + "</br>

下次运行时,值将为:

<br> Key: " + A + ", Value: " + 1 + "</br>
<br> Key: " + A + ", Value: " + 1 + "</br>
<br> Key: " + B + ", Value: " + 2 + "</br>
<br> Key: " + B + ", Value: " + 2 + "</br>

在下一次运行时将是:

<br> Key: " + A + ", Value: " + 1 + "</br>
<br> Key: " + A + ", Value: " + 1 + "</br>
<br> Key: " + A + ", Value: " + 1 + "</br>
<br> Key: " + B + ", Value: " + 2 + "</br>
<br> Key: " + B + ", Value: " + 2 + "</br>
<br> Key: " + B + ", Value: " + 2 + "</br>

可能是什么问题?

0 个答案:

没有答案