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

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


This error raised up because you trying to update dict object by using a wrong sequence (list or tuple) structure.

cash_id.create(cr, uid, lines,context=None) trying to convert lines into dict object:

(0, 0, {    'name': l.name,    'date': l.date,    'amount': l.amount,    'type': l.type,    'statement_id': exp.statement_id.id,    'account_id': l.account_id.id,    'account_analytic_id': l.analytic_account_id.id,    'ref': l.ref,    'note': l.note,    'company_id': l.company_id.id})

Remove the second zero from this tuple to properly convert it into a dict object.

To test it your self, try this into python shell:

>>> l=[(0,0,{'h':88})]>>> a={}>>> a.update(l)Traceback (most recent call last):  File "<pyshell#11>", line 1, in <module>    a.update(l)ValueError: dictionary update sequence element #0 has length 3; 2 is required>>> l=[(0,{'h':88})]>>> a.update(l)


I was getting this error when I was updating the dictionary with the wrong syntax:

Try with these:

lineItem.values.update({attribute,value})

instead of

lineItem.values.update({attribute:value})


One of the fast ways to create a dict from equal-length tuples:

>>> t1 = (a,b,c,d)>>> t2 = (1,2,3,4)>>> dict(zip(t1, t2)){'a':1, 'b':2, 'c':3, 'd':4, }