我正在使用python词典执行我的任务之一,并且此错误提示与以下提及的语句有关。
def flat(self, data, no_of_attrs):
if isinstance(data, list):
if len(data) == 1:
self.flat(data[0], no_of_attrs)
elif len(data) > 1:
for j in data:
self.flat(j, no_of_attrs)
else:
return
#if dictionary
else:
if len(data)==1:
if data['parent_id']==0 or 1:
self.flat(self, data['children_data'], no_of_attrs)
else:
n_item = item(data['id'], data['parent_id'], data['name'], data['is_active'], data['position'], data['product_count'], data['path'], data['name_ar'])
发生的错误与条件if data['parent_id']==0 or 1:
有关。
有人可以看到这个问题,并帮助我解决这个问题。
[{"id": 6, "parent_id": 5, "name": "Boots", "enabled": true, "position": 1, "children_data": [], "path": "/women/shoes/boots"}, {"id": 1523, "parent_id": 5, "name": "Flats", "enabled": true, "position": 2, "children_data": [], "path": "/women/shoes/flats"}, {"id": 16, "parent_id": 5, "name": "Ballerinas", "enabled": true,"count": 12505, "children_data": [], "path": "/women/shoes/ballerinas"}]
PS:-数据是字典