我正在将odoo 11,python 2.7移植到python 3.我已经编辑了一个属于odoo,python代码的插件。
代码是:
vat = invoice.partner_id.vat or ''
vat = list(filter(lambda x: x.isnumeric(), vat[:2])) + vat[2:]
错误是:
TypeError: can only concatenate list (not "str") to list
我该如何解决这个问题,这个代码有什么问题?请帮我。
list(filter(lambda x: x.isnumeric(), vat[:2]))
上面的操作总是返回列表。
vat = invoice.partner_id.vat or ''
or ''
)。如果你期望你的type(vat)==list
,你应该使用
vat = invoice.partner_id.vat or []
如果您期望type(vat)==str
,您应该将过滤后的列表转换为str
"".join(list(filter(lambda x: x.isnumeric(), vat[:2]))) + vat[2:]
使用线
vat = invoice.partner_id.vat or ''
#convert string to list
vat = [x for x in val]
vat = list(filter(lambda x: x.isnumeric(), vat[:2])) + vat[2:]
首先将字符串转换为列表。