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

后端 未结 14 1076
梦如初夏
梦如初夏 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:38

    Error in your question is raised when you try something like following:

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

    It's hard to tell where is the cause in your code unless you show your code, full traceback.

    0 讨论(0)
  • 2020-11-29 22:40

    Here is the reproduced error.

    >>> d = {}
    >>> d.update([(1,)])
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    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 "<stdin>", line 1, in <module>  
    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.

    0 讨论(0)
提交回复
热议问题