Same Variable打印循环外部列表中的所有内容,但在循环内部仅打印最后一个附加值。为什么?

时间:2013-07-17 08:35:32

标签: python django

该问题不言自明。变量是reply_list。

def db_query():

    chat_data = {}
    queries = A.objects.filter(is_responded = 0)
    for query in queries:
        replies = []
        c_id = query.conversation_id
        b_ids = json.loads(query.sent_to)
        b_ids = b_ids["business_ids"]

        for index in range(len(b_ids)):
            b_ids[index] = int(b_ids[index])

        for b_id in b_ids:

            representative_reply = B.objects.filter(conversation_id = c_id , b_id = b_id)
            user_reply = A.objects.filter(conversation_id = c_id)
            replies.append(chain(representative_reply , user_reply))
            reply_list =[]
            for reply in replies:
                for r in reply:
                    reply_list.append(r.u_query)

            print reply_list               # prints the complete list. But when inside the loop , prints only the last appended value..........SEE DOWN........
            business_data = C.objects.filter(b_id = b_id)

            for data in business_data:
                print reply_list              # prints only the last appended value .... Why? 

我想要的是完整的reply_list应该打印在business_data循环中。

请提出任何建议。哪里出错了。

0 个答案:

没有答案