Attributeerror: 'nonetype' Object Has No Attribute 'add'
I got the following error AttributeError: 'NoneType' object has no attribute 'add' while I tried this. not_yet_bought_set = set() . . . for value in set_dict.itervalues(): f
Solution 1:
not_yet_bought_set.add(item)
this will return None
and you are assigning it to not_yet_bought_set
. So, not_yet_bought_set
becomes None
now. The next time
not_yet_bought_set = not_yet_bought_set.add(item)
is executed, add
will be invoked on None
. Thats why it fails.
To fix this, simply do this. Dont assign this to anything.
not_yet_bought_set.add(item)
Solution 2:
set.add
returns nothing.
>>>s = set()>>>the_return_value_of_the_add = s.add(1)>>>the_return_value_of_the_add isNone
True
Replace following line:
not_yet_bought_set = not_yet_bought_set.add(item)
with:
not_yet_bought_set.add(item)
Post a Comment for "Attributeerror: 'nonetype' Object Has No Attribute 'add'"