列表和字典结合使用

这里主要是列表和字典的结合使用
class sys_develop_info(View):
    # 开发信息
    def get(self,request):
        filepath = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + '/requirement.txt'
        with open(filepath, 'r') as f:
            readline = f.readlines()
            V_list = []
            for i in readline:
                dict_list = {}
                ll = i.replace("\n", "")
                i_list = ll.split("==")
                dict_list["name"] = i_list[0];
                dict_list["info"] = "v" + i_list[1]
                V_list.append(dict_list)
        return HttpResponse(json.dumps(V_list), content_type='application/json')

你可能感兴趣的:(列表和字典结合使用)