值错误:对象forloop中的值太多,无法解包

2024-10-02 22:37:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我在尝试设置对象列表时遇到以下错误。以前我的数据不是这样的,但现在是这样了

有没有更好的方法来编写obj_list_dictize方法来处理这类问题

谢谢

Module ckan.lib.dictization:79 in obj_list_dictize
>>  obj, capacity = obj
ValueError: too many values to unpack  

def obj_list_dictize(obj_list, context, sort_key=lambda x:x):
    '''Get a list of model object and represent it as a list of dicts'''

    result_list = []
    active = context.get('active', True)

    for obj in obj_list:
        if context.get('with_capacity'):
            obj, capacity = obj
            dictized = table_dictize(obj, context, capacity=capacity)
        else:
            dictized = table_dictize(obj, context)
        if active and obj.state != 'active':
            continue
        result_list.append(dictized)

    return sorted(result_list, key=sort_key)

Tags: andof方法keyinobjgetcontext