跳至内容
菜单
此问题已终结
3 回复
5754 查看

def map_field2write(self, field2write):
        res = {}
        field_names = self._get_fieldnames()
        for fn in field2write.keys():
            if fn not in field_names:
               continue
            else:
               res[field_names[fn]] = field2write[fn]
        return res


what is the error?



形象
丢弃
编写者

I tried if condition, but still error.

最佳答案

Error clearly says field2write 'bool' object has no attribute 'keys'
To avoid check is fiel2write contain value and type dict then other line code execute

Example:

Check

if field2write:

    for fn in field2write.keys():

形象
丢弃
最佳答案

Hi,

You can try update the method as below

def map_field2write(self, field2write):
res = {}
if not field2write:
return res
field_names = self._get_fieldnames()
for fn in field2write.keys():
if fn not in field_names:
continue
else:
res[field_names[fn]] = field2write[fn]

return res

Regards

形象
丢弃