Error: “dictionary update sequence element #0 has length 1; 2 is required” on Django 1.4

后端 未结 14 1090
梦如初夏
梦如初夏 2020-11-29 21:43

I have an error message on django 1.4:

dictionary update sequence element #0 has length 1; 2 is required

[EDIT]

It happe

14条回答
  •  旧巷少年郎
    2020-11-29 22:40

    Here is the reproduced error.

    >>> d = {}
    >>> d.update([(1,)])
    Traceback (most recent call last):
      File "", line 1, in 
    ValueError: dictionary update sequence element #0 has length 1; 2 is required
    >>> 
    >>> d
    {}
    >>> 
    >>> d.update([(1, 2)])
    >>> d
    {1: 2}
    >>> 
    >>> d.update('hello_some_string')
    Traceback (most recent call last):
    File "", line 1, in   
    ValueError: dictionary update sequence element #0 has length 1; 2 is required
    >>> 
    

    If you give the sequence and any element length is 1 and required two then we will get this kind of error. See the above code. First time I gave the sequence with tuple and it's length 1, then we got the error and dictionary is not updated. second time I gave inside tuple with with two elements, dictionary got updated.

提交回复
热议问题