Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: descriptor 'append' requires a 'list' object but received a 'dict' [closed]

Tags:

python

In the for loop I have a dictionary object like this:

mob1 = {
    "Item": item1,
    'Price': price1,
    'Desc': desc1
}

and I tried to append it like:

list.append(mob1)

I get the following error:

Traceback (most recent call last):
  File "/home/turbolab/Documents/python_test/Sep 23 data_to_json test.json", line 32, in <module>
    list.append(mob1)
TypeError: descriptor 'append' requires a 'list' object but received a 'dict'
like image 683
arjun Avatar asked Sep 24 '16 14:09

arjun


1 Answers

list is a class. append is a method of that class which has to be called on instances of list.

list.append(7)  # error

mylist = list()
mylist.append(7)  # ok
like image 150
zvone Avatar answered Nov 14 '22 20:11

zvone